Android > 권한설정
Redjini WiKi
권한 확인
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
//권한 있음
}else{
//권한 없음
}
권한 요청
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.READ_EXTERNAL_STORAGE ,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_CONTACTS}, REQUEST_CODE);
응답 확인
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_CODE) {
//permissions에 대해서 각각 권한 승인 여부 확인
}
}
앱 정보 실행하기
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getPackageName()));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY );
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivityForResult(intent, REQUEST_SETTINGS);