14

I get the following Exception while running on a Android 6 device.

java.lang.SecurityException: Missing android.permission.GET_ACCOUNTS

This looks like a fairly straight forward exception, but for me it's not. My manifest looks like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..." >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

<application
    ...

The piece of code which throws this exception is the following line:

mLoggedInEmail = Plus.AccountApi.getAccountName(mGoogleApiClient);

On an android 5 device it works just fine.

1 Answer 1

23

Starting with Android M, API 23, you need to request some permission at runtime on top of declaring them in your manifest.

See this link for more info: https://developer.android.com/training/permissions/requesting.html

As a quick workaround, you can set your targetSdkVersion to 22 in your build.gradle.

Keep in mind that even with this workaround, if the user goes in setting in disable the permission for your app, your app will crash.

This is the list of permissions impacted by this new change:

  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION
  • ADD_VOICEMAIL
  • BODY_SENSORS
  • CALL_PHONE
  • CAMERA
  • GET_ACCOUNTS
  • PROCESS_OUTGOING_CALLS
  • READ_CALENDAR
  • READ_CALL_LOG
  • READ_CELL_BROADCASTS
  • READ_CONTACTS
  • READ_EXTERNAL_STORAGE
  • READ_PHONE_STATE
  • READ_SMS
  • RECEIVE_MMS
  • RECEIVE_SMS
  • RECEIVE_WAP_PUSH
  • RECORD_AUDIO
  • SEND_SMS
  • USE_SIP
  • WRITE_CALENDAR
  • WRITE_CALL_LOG
  • WRITE_CONTACTS
  • WRITE_EXTERNAL_STORAGE
2
  • how to request on runtime? and check if access is given or not Aug 4, 2016 at 16:45
  • I am missing USE_CREDENTIALS after updating to android 2.2 and using SDK version 24 for the project.
    – DVG
    Oct 21, 2016 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.