주셔서 감사합니다, 당신이 요구하는지 정확히 모르겠어요,하지만 당신은 사용자가 원래 shouldShowRequestPermissionRationale
를 사용하여 위치 권한에 동의 여부를 테스트 할 수 있습니다.
다음은 내가 사용하고 있으며 도움이되는 Requestion Permissions 설명서에 기반한 확장 코드입니다.
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "checkMyPermissions (" + permissionRequestCode + ") : Permissions FAILED");
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
new AlertDialog.Builder(this)
.setMessage("In order to show data this app requires location permissions")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
permissionRequestCode);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
permissionRequestCode);
}
return false;
} else {
Log.d(TAG, "checkMyPermissions (" + permissionRequestCode + ") : Permissions Passed");
return true;
}
당신이 무엇을 요구하고 있는지 분명하지 않습니다. 무엇이 사용자를 다시 알릴 수 없게합니까? –