A>퍼미션 설정하기
1
2
3
4
|
<permission android:name="com.test.permission.SOME_PERMISSION"
android:label="SOME Permission"
android:description="@string/permission"
android:protectionLevel="normal"/>
|
cs |
1.속성 종류
name: 퍼미션의 이름
label, description: 퍼미션에 대한 설명(사용자에게 보이는 문자열)
protectionLevel: 보호 수준
protectionLevel을 이용해 보호 수준
normal: 낮은 수준의 보호. 사용자에게 권한 부여 요청이 필요 없는 경우
dangerous: 높은 수준의 보호. 사용자에게 권한 부여 요청이 필요한 경우
signature: 동일한 키로 사인된 앱만 실행
signatureOrSystem: 안드로이드 시스템 앱이거나 동일 키로 사인된 앱만 실행
2. 퍼미선의 적용
--컴포넌트에 퍼미션 적용
1
2
3
4
5
6
7
|
<activity android:name=".SomeActivity"
android:permission="com.test.permission.SOME_PERMISSION">
<intent-filter>
<action android:name="AAA"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
|
cs |
--퍼미션이 부여된 컴포넌트를 샤용할 때
1
2
3
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test">
<uses-permission android:name="com.test.permission.SOME_PERMISSION"/>
</manifest>
|
cs |
3.퍼미션 상태의 확인
1
2
3
4
5
6
|
if(ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_EXTERNAL_STORAGE) ==
PackageManager.PERMISSION_GRANTED){
//...
}
|
cs |
1
2
3
4
|
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},200 );
|
cs |
1
2
3
4
5
6
7
8
9
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(requestCode==200 && grantResults.length>0) {
if(grantResults[0]==PackageManager.PERMISSION_GRANTED)
if(grantResults[1]==PackageManager.PERMISSION_GRANTED)
}
} }
|
cs |