Android 6.0 permission.GET_ACCOUNTS

后端 未结 6 965
予麋鹿
予麋鹿 2020-12-24 11:47

I\'m using this to get permission:

if (ContextCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {

         


        
6条回答
  •  醉梦人生
    2020-12-24 12:20

    If your using the GET_ACCOUNTS permission to ask the user to select a particular account type on the device(Google in my case), you can use the AccountPicker class which doesn't require any special permissions

    Intent intent = AccountPicker.newChooseAccountIntent(null, null,
                        new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
                        false, null, null, null, null);
    try {
        startActivityForResult(intent, REQUEST_ACCOUNT_PICKER);
    } catch (ActivityNotFoundException e) {
        // This device may not have Google Play Services installed.
    }
    

    You'll need Google Play services auth in your gradle dependencies

    implementation com.google.android.gms:play-services-auth:16.0.1
    

    This avoids the Contacts permission popup for me

提交回复
热议问题