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.

Joshude
  • 183
  • 1
  • 8

1 Answers1

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
Distwo
  • 11,569
  • 8
  • 42
  • 65