My AndroidManifest:

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>


My build.gradle:
classpath 'com.android.tools.build:gradle:2.1.2'


My Activity's `onCreate()`:

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
                if (ContextCompat.checkSelfPermission(this,
                        Manifest.permission.GET_ACCOUNTS)
                        != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(AnyMailMainActivity.
this,
                                new String[]{Manifest.permission.
GET_ACCOUNTS},
                                MY_PERMISSIONS_REQUEST_READ_CONTACTS);
                } else {
                    mContactPermissionGranted = true;
                }
            } else {
                mContactPermissionGranted = true;
            }


My `onRequestPermissionsResult()`:

    @Override
        public void onRequestPermissionsResult(int requestCode, String[] 
permissions, int[] grantResults) {
            switch (requestCode) {
                case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
                    // If request is cancelled, the result arrays are empty.
                    if (grantResults.length > 0
                            && grantResults[0] == PackageManager.
PERMISSION_GRANTED) {
                        mContactPermissionGranted = true;
                    } else {
                        mContactPermissionGranted = false;
                    }
                    return;
                }
            }
        }

Still, I am neither getting a 'request contact dialog' nor getting any 
permission granted for GET_ACCOUNTS.
The purpose is to get the google emails from the device for Android M and 
above without showing google's account picker. Just the way we used to get 
the list of accounts before Android M.

-Nishant

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/8eda0f38-4c59-40eb-948f-0095253ccbd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to