0

I want to put the PHONE_CALLS and PROCESS_OUTGOING_CALLS permissions on the same method, so when the user first opens the app, accept the two permissions together. It is possible ? Reading the official documentation: https://google-developer-training.gitbooks.io/android-developer-phone-sms-course/content/Lesson%201/1_c_phone_calls.html was not very clear to me. Follow the code:

public boolean isPermissionGranted() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(android.Manifest.permission.PROCESS_OUTGOING_CALLS)
                    == PackageManager.PERMISSION_GRANTED) {
                Log.v("TAG", "Permission is granted");
                return true;

            } else {

                Log.v("TAG", "Permission is revoked");
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.PROCESS_OUTGOING_CALLS}, 1);
                return false;
            }
        } else { //permission is automatically granted on sdk<23 upon installation
            Log.v("TAG", "Permission is granted");
            return true;
        }
    }

And:

if (ContextCompat.checkSelfPermission(MainActivity.this,
            Manifest.permission.PROCESS_OUTGOING_CALLS)
            != PackageManager.PERMISSION_GRANTED) {


        if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this,
                Manifest.permission.PROCESS_OUTGOING_CALLS)) {


        } else {

            ActivityCompat.requestPermissions(MainActivity.this,
                    new String[]{Manifest.permission.PROCESS_OUTGOING_CALLS},
                    MY_PERMISSIONS_REQUEST_CALL_PHONE);
        }
    }
Luiz Santos
  • 55
  • 11

2 Answers2

2

You put the requested permission in a string array, so you can just put both permissions in the same array, seperated by comma

new String[]{permission1, permission2}
Soenke K
  • 51
  • 5
1

Both of the permissions you are trying to request are part of the same permissions group. You only need to have one permission granted to have access to the rest of the group's permissions (in this case: phone). You don't need to request both, just prompt the user for one and carry on.

Here all all the permissions that are part of the phone permissions group:

READ_PHONE_STATE
READ_PHONE_NUMBERS
CALL_PHONE
ANSWER_PHONE_CALLS
READ_CALL_LOG
WRITE_CALL_LOG
ADD_VOICEMAIL
USE_SIP
PROCESS_OUTGOING_CALLS

No matter which permission in the group you request, the user will see it the same way (if they are on API 23+) example:

permissions

You will still need to add all permissions you are using in the manifest for users that are not on API 23+ (6.0).

See: https://developer.android.com/guide/topics/permissions/overview#perm-groups for more information

Eric Bachhuber
  • 3,872
  • 2
  • 19
  • 26
  • Thanks man, i got it, but only with outgoing calls permission, I can not make my button an outgoing call for a certain number to work, even after I accept the permission, then I have to go to device configs, and reject and accept the permission again. You have some idea of what can be? – Luiz Santos Jul 02 '18 at 19:46
  • Did you add both to your `AndroidManifest.xml`? Hard to say what the problem is without seeing more code. – Eric Bachhuber Jul 02 '18 at 19:47