Я создаю AlertDialog и вызываю StartActivityForRessult () внутри него.Но никогда не перезванивать onActivityResult ().Как решить эту проблему?Я пытался поставить getActivity (). StratActivityForResult (), но это не работает.Как правильно вызывать startActivityForResult () внутри AlertDilaog и возвращать результат обратно в onActivityResult () действия?
if(ActivityCompat.shouldShowRequestPermissionRationale(this,perName)){
//TOdo: show dailog box explaining the permissions requirment
showDialog("Please note", "This app needs ..... permissions to work with all the features wothout any problem in future", "Yes, Grant pernissions",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
checkRequestForPermissions();
}
}, "No, Exit App", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
finish();
}
}, false);
}else{
pickPermissions();
break;
}
private void pickPermissions(){
showDialog("", "You have denied some necessary permissions permanently"
+ " We will direct you to [Settings] screen, Turn on all permissions at [Settings] -> [Permissions].",
"Go To Settings", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//Todo: open setting screen for permission result
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, REQUEST_PERMISSION_SETTING);
//finish();
}
}, "No, Close App", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
},false);
}
public AlertDialog showDialog(String title, String msg, String positiveLabel,
DialogInterface.OnClickListener positiveOnClick,
String negativeLabel, DialogInterface.OnClickListener negativeOnClick,
boolean isCancelAble){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage(msg);
builder.setCancelable(isCancelAble);
builder.setPositiveButton(positiveLabel, positiveOnClick);
builder.setNegativeButton(negativeLabel, negativeOnClick);
AlertDialog alert = builder.create();
alert.show();
return alert;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if (requestCode == REQUEST_PERMISSION_SETTING && resultCode == RESULT_OK){
if(checkRequestForPermissions()){
//Todo: start normal flow
Toast.makeText(this, "Returned and granted successfully", Toast.LENGTH_LONG);
}
}
super.onActivityResult(requestCode, resultCode, data);
}