Reputation: 99
in my app while pressing the allow button it's not calling action method once the permission granted after that it's working fine here i'm using fragment for this so how to call action method when allow button pressed any solution.
// variable declaration
private static final int MY_PERMISSIONS_REQUEST_PHONE_CALL = 11;
// method with onClick listener
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ContextCompat.checkSelfPermission(getActivity(),
android.Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
android.Manifest.permission.CALL_PHONE)) {
} else {
ActivityCompat.requestPermissions(getActivity(),
new String[]{android.Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_PHONE_CALL);
}
}
else {
CallPErmission();
}
}
});
// onrequest permission
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_PHONE_CALL:
if(grantResults.length>0 && permissions[0].equals(android.Manifest.permission.CALL_PHONE)){
if(grantResults[0]==PackageManager.PERMISSION_GRANTED )
{
CallPErmission();
}
}
break;
}
}
Upvotes: 0
Views: 842
Reputation: 5598
Why don't you use your fragment requestPermission
method instead of the ActivityCompat
one and get the result by overriding onRequestPermissionsResult
on your fragment?
Upvotes: 2