Revoked Permission Android.permission.call_phone
Solution 1:
Permission CALL_PHONE belong to dangerous permission group. So if your apps target SDK is 23 or higher and your device is running on Android 6.0 or higher, you must request for CALL_PHONE permission while the app is running.
Example :
Stringnumber = ("tel:" + numTxt.getText());
mIntent = newIntent(Intent.ACTION_CALL);
mIntent.setData(Uri.parse(number));
// Here, thisActivity is the current activityif (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(thisActivity,
newString[]{Manifest.permission.CALL_PHONE},
MY_PERMISSIONS_REQUEST_CALL_PHONE);
// MY_PERMISSIONS_REQUEST_CALL_PHONE is an// app-defined int constant. The callback method gets the// result of the request.
} else {
//You already have permissiontry {
startActivity(mIntent);
} catch(SecurityException e) {
e.printStackTrace();
}
}
When your app requests permissions, the system presents a dialog box to the user. When the user responds, the system invokes your app's onRequestPermissionsResult() method, passing it the user response.
@OverridepublicvoidonRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_CALL_PHONE: {
// If request is cancelled, the result arrays are empty.if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// permission was granted, yay! Do the phone call
} else {
// permission denied, boo! Disable the// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other// permissions this app might request
}
}
Solution 2:
In android 6.0 (Api lvl 23) we have something called "Runtime Permissions". You have to read about it.
You can find documentation here.
Solution 3:
You code could works only if you make an ACTION_DIAL
, not an ACTION_CALL
where you need to request a permission, so if you want to make a call, please follow this example:
MANIFEST:
<uses-permissionandroid:name="android.permission.CALL_PHONE" />
Code:
importstatic android.Manifest.permission.CALL_PHONE;
Intenti=newIntent(Intent.ACTION_CALL);
i.setData(Uri.parse("tel:0612312312"));
/*
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData(Uri.parse("tel:0612312312"));
if (i.resolveActivity(getPackageManager()) != null) {
startActivity(i);
}*/if (ContextCompat.checkSelfPermission(getApplicationContext(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
startActivity(i);
} else {
requestPermissions(newString[]{CALL_PHONE}, 1);
}
Solution 4:
in fragment class
Step 1: import static android.Manifest.permission.CALL_PHONE;
step 2:Where your onclick button:
IntentcallIntent=newIntent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" +driver_no ));
if (ContextCompat.checkSelfPermission(getActivity(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
startActivity(callIntent);
} else {
requestPermissions(newString[]{CALL_PHONE}, 1);
}
[Or] you are using in activity class means change the getActivity to getApplicationContext()
Solution 5:
FYI: If you're targeting Android 11, you need to add an Intent Query element for Intent.ACTION_DIAL in your manifest.
https://developer.android.com/training/basics/intents/package-visibility#intent-signature
Post a Comment for "Revoked Permission Android.permission.call_phone"