Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revoked permission android.permission.CALL_PHONE

Tags:

I'm trying to programmatically call to a number with following code:

 String number = ("tel:" + numTxt.getText());  Intent intent = new Intent(Intent.ACTION_CALL);  intent.setData(Uri.parse(number));  startActivity(intent); 

I've set the permission in the Manifest:

<uses-permission android:name="android.permission.CALL_PHONE"/> 

I'm working with real device for testing and debugging, it is Nexus 5 with Android M, my compileSdkVersion is 23. I'm getting the following Security Exception:

error: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{cbbd7c1 5228:com.dialerTest.DialerApp/u0a96} (pid=5228, uid=10096) with revoked permission android.permission.CALL_PHONE 

I've searched the web and this community for similar Q/A and couldn't find the answer. Any help will be appreciated.

like image 525
Evgeniy Mishustin Avatar asked Nov 02 '15 08:11

Evgeniy Mishustin


People also ask

What is CALL_PHONE permission?

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 : String number = ("tel:" + numTxt.

What is Access_coarse_location and Access_fine_location?

ACCESS_COARSE_LOCATION. Allows an app to access approximate location. String. ACCESS_FINE_LOCATION. Allows an app to access precise location.

What is READ_PHONE_STATE permission?

READ_PHONE_STATE is one of the Android permissions categorized as dangerous. This is because it “allows read only access to phone state, including the phone number of the device, current cellular network information, the status of any ongoing calls, and a list of any Phone Accounts registered on the device” [2] .


2 Answers

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 :

String number = ("tel:" + numTxt.getText()); mIntent = new Intent(Intent.ACTION_CALL); mIntent.setData(Uri.parse(number)); // Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(thisActivity,             Manifest.permission.CALL_PHONE)     != PackageManager.PERMISSION_GRANTED) {      ActivityCompat.requestPermissions(thisActivity,             new String[]{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 permission      try {         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.

@Override public void onRequestPermissionsResult(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   } } 
like image 59
Faisal T Avatar answered Sep 19 '22 13:09

Faisal T


In android 6.0 (Api lvl 23) we have something called "Runtime Permissions". You have to read about it.

You can find documentation here.

like image 33
Artur Szymański Avatar answered Sep 19 '22 13:09

Artur Szymański