ユーザーにCamera, Location, Write Storage, CallPhone
権限を要求し、ユーザーが権限を拒否した場合に警告ダイアログを表示します。すべての権限を拒否した後に処理を続行できません
しかし、私のコードは、この例外がスローされます。
E/AndroidRuntime:致命的な例外:メイン プロセス:fwt_android.mpermissions、PID:4850 java.lang.RuntimeException:失敗提供結果ResultInfo {=を@ {fwt_android.mpermissions/fwt_android.mpermissions.activities.Splash}アクティビティには、アンドロイド:requestPermissions :,リクエスト= 1、結果= -1、データ=インテント{act = android.content.pm.action.REQUEST_PERMISSIONS(エクストラ) :android.content.res.Resources $ NotFoundException:リソースID#0x0 android.app.ActivityThread.deliverResults(ActivityThread.java:3699)012 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1393)でandroid.app.ActivityThread.-wrap16(ActivityThread.java) でandroid.app.ActivityThread.handleSendResult(ActivityThread.java:3742) で android.os.Handler.dispatchMessage(Handler.java:102) とandroid.os.Looper.loop(Looper.java:148) とandroid.app.ActivityThread.main(ActivityThread.java:5417) でのjava .lang.reflect.Method.invoke(ネイティブメソッド) com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit。メイン(ZygoteInit.java:616) 原因:android.content.res.Resources $ NotFoundException:リソースID#0x0 android.content.res.Resources.getValue(Resources.java:1351) android.content。 res.Resources.loadXmlResourceParser(Resources.java:2774) android.content.res.Resources.getLayout(Resources.java:1165) (android.view.LayoutInflater.inflate(LayoutInflater.java:421) 、android)にあります。 view.LayoutInflater.inflate(LayoutInflater.java:374)android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)の android.support.v7.app.AppCompatDialog.setContent View(AppCompatDialog.java:83) android.support.v7.app.AlertController.installContent(AlertController.java:226) android.support.v7.app.AlertDialog.onCreate(AlertDialog.java:260) at android.app.Dialog.dispatchOnCreate(Dialog.java:394)android.app.Dialog.showの (Dialog.java:295) at fwt_android.mpermissions.activities.Splash.onRequestPermissionsResult(Splash.java:215) at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6553)android.app.Activity.dispatchActivityResult(Activity.java:6432)の (android.app.ActivityThread.deliverResults(ActivityThread.java:369)) 5) android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) (android.app.ActivityThread.-wrap16(ActivityThread.java)) (android.app.ActivityThread)$ H.handleMessage(ActivityThread.java:1393) ) android.os.Handler.dispatchMessage(Handler.java:102) (android.os.Looper.loop(Looper.java:148) 、android.app.ActivityThread.main(ActivityThread。java:5417) at java.lang.reflect.Method.invoke(ネイティブメソッド) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os .ZygoteInit.main(ZygoteInit.java:616)ここで
は、権限をチェックするための定数である - ここで
private final int PERMISSION_CALLBACK_CONSTANT = 1;
private final int REQUEST_PERMISSION_SETTING = 1;
String[] permissionsRequired = new String[]{Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CALL_PHONE};
はpermisionsをチェックするための私のコードです -
public void checkPermission() {
if (ActivityCompat.checkSelfPermission(context, permissionsRequired[0]) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(context, permissionsRequired[1]) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(context, permissionsRequired[2]) != PackageManager.PERMISSION_GRANTED
|| ActivityCompat.checkSelfPermission(context, permissionsRequired[3]) != PackageManager.PERMISSION_GRANTED
) {
if (ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissionsRequired[0])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissionsRequired[1])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissionsRequired[2])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissionsRequired[3])) {
//Show Information about why you need the permission
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Need Multiple Permissions");
builder.setMessage("This app needs Camera Location, Storage and Phone permissions.");
builder.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
ActivityCompat.requestPermissions(Splash.this, permissionsRequired, PERMISSION_CALLBACK_CONSTANT);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
}).create().show();
} else if (permissionStatus.getBoolean(permissionsRequired[0], false)
|| permissionStatus.getBoolean(permissionsRequired[1], false)
|| permissionStatus.getBoolean(permissionsRequired[2], false)
|| permissionStatus.getBoolean(permissionsRequired[3], false)
) {
//Previously Permission Request was cancelled with 'Dont Ask Again',
// Redirect to Settings after showing Information about why you need the permission
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Need Multiple Permissions");
builder.setMessage("This app needs Camera, Location, Storage and Phone permissions.");
builder.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
sentToSettings = true;
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, REQUEST_PERMISSION_SETTING);
// Toast.makeText(getApplicationContext(), "Go to Permissions to Grant Camera and Location", Toast.LENGTH_LONG).show();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
finish();
}
}).create().show();
} else {
//just request the permission
ActivityCompat.requestPermissions(Splash.this, permissionsRequired, PERMISSION_CALLBACK_CONSTANT);
}
SharedPreferences.Editor editor = permissionStatus.edit();
editor.putBoolean(permissionsRequired[0], false);
editor.putBoolean(permissionsRequired[1], false);
editor.putBoolean(permissionsRequired[2], false);
editor.putBoolean(permissionsRequired[3], false);
editor.apply();
} else {
//You already have the permission, just go ahead.
splashTread.start();
}
}
、ここでコールバック関数です -
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_CALLBACK_CONSTANT) {
//check if all permissions are granted
boolean allgranted = false;
for (int grantResult : grantResults) {
if (grantResult == PackageManager.PERMISSION_GRANTED) {
allgranted = true;
} else {
allgranted = false;
break;
}
}
if (allgranted) {
splashTread.start();
} else if (ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissions[0])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissions[1])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissions[2])
|| ActivityCompat.shouldShowRequestPermissionRationale(Splash.this, permissions[3])) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Need Multiple Permissions");
builder.setMessage("This app needs Camera, Location, Storage and Phone permissions.");
builder.setPositiveButton("Grant", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
ActivityCompat.requestPermissions(Splash.this, permissionsRequired, PERMISSION_CALLBACK_CONSTANT);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
finish();
}
}).create().show();
} else {
Toast.makeText(getBaseContext(), "Unable to get Permission", Toast.LENGTH_LONG).show();
}
}
}
そしてsplashThread()
機能、私はすべての権限を拒否して進める際に新しい警告ダイアログがすべき正しい作業されるが、すべての権限が付与されたときに待機する機能ですユーザーに設定を送信するために表示されるが、時刻にアプリケーションがクラッシュするbuilder.show();
私はなぜクラス全体をデバッグしてもこのエラーが出るのか分からない。 エラーとその解決策を見つけてもらえますか?