最初のページで構造化されていますが、すぐに許可された(書き込み)後にDialogを開くことができません。初めてPermissionに尋ねられ、onRequestPermissionsResult()でPermissionを与えました。私はDialogを開きました。ここではAppが閉じられています。残念なことにAPPはクラッシュしました。ここでは問題を再開すると、正常に動作しています。モニタで問題が発生しました。
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
.I検索されたロットですが、私は見たことのある答えが異なっています。なぜ、アプリが最初にクラッシュしたのか分かりません。ここ は私のコードです:書き込み権限を付与した後、アプリケーションが初めてクラッシュしましたか?
llAddPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!tvAddPhotoOrNext.getText().toString().equals("Next")) { // When Image not gone selected
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//First checking if the app is already having the permission
if (isReadStorageAllowed()) {
//If permission is already having then showing the toast
Toast.makeText(AddUserProfilePic.this, "You already have the permission", Toast.LENGTH_LONG).show();
//Existing the method with return
showFourButtonsBSDialog();
}else {
//If the app has not the permission then ask for the permission
checkPermissions();
}
} else
showFourButtonsBSDialog();
} else { // When image gone selected.
mSetProfilePicByAPI();
}
}
});
@SuppressLint("InlinedApi")
private void checkPermissions() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PICKIMAGE);
} else {
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_PICKIMAGE:
//If permission is granted
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//Displaying a toast
Toast.makeText(this, "Permission granted now you can read the storage", Toast.LENGTH_LONG).show();
showFourButtonsBSDialog();
} else {
//Displaying another toast if permission is not granted
Toast.makeText(this, "Oops you just denied the permission", Toast.LENGTH_LONG).show();
}
}
}
/* BottomSheetDialog */
private void showFourButtonsBSDialog() {
MoreOptionsDialogFragment mTBFragment = new MoreOptionsDialogFragment(); // ThreeButtonsFragment
Bundle mTextNamesArgs = new Bundle(); //Send buttons names
mTextNamesArgs.putStringArray("buttons_names",new String[]{"Take Photo","Choose from library",
"Photo from Facebook","Photo from Instagram"});
mTBFragment.setArguments(mTextNamesArgs);
mTBFragment.show(getSupportFragmentManager(),mTBFragment.getTag());
}
private boolean isReadStorageAllowed() {
//Getting the permission status
int result = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
//If permission is granted returning true
if (result == PackageManager.PERMISSION_GRANTED)
return true;
//If permission is not granted returning false
return false;
}
minSdkVersionは、19と targetSdkVersion 25です。 – Lokesh
次の回答の解決策を試すことができますか。 https://stackoverflow.com/a/10261449/8109872 – Fio
これは質問への答えを提供しません。十分な[評判](https://stackoverflow.com/help/whats-reputation)があれば、[投稿にコメントする]ことができます(https://stackoverflow.com/help/privileges/comment)。代わりに、[質問者からの明確化を必要としない回答を提供する](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can- i-do-代わりに)。 - [レビューから](/レビュー/低品質の投稿/ 17864323) – Redman