Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android M - GoogleAccountCredential setSelectedAccount doesn't work - name must not be null

On the Android M-Preview GoogleAccountCredential.setSelectedAccount doesn't seem to work.

When debugging, I noticed that after calling that method, the selectedAccount and accountName fields of the object are still null.

While debugging you can see that my variable accountName is not empty or null, I call the .setSelectedAccountName(), but as you can see in the debug window, the field in the GoogleAccountCredential is still null.

Debugging window code Debugging window debug values

I think this can be related to some permissions? On my Manifest, I have the following permissions declared:

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

I know that the GET_ACCOUNTS permission you get for free on M (According to https://developer.android.com/preview/features/runtime-permissions.html#normal ), but the other two permissions are "unknown" to the M-Preview. So maybe, it's that?

like image 747
Christian Göllner Avatar asked Aug 28 '15 11:08

Christian Göllner


1 Answers

android.permission.GET_ACCOUNTS has protectionLevel:dangerous and is now part of the Contacts permission group, which means you should request it at runtime using the new Activity.requestPermissions()

Only then can you interact with accounts created by other apps on your device.

like image 159
wojtek.kalicinski Avatar answered Sep 21 '22 13:09

wojtek.kalicinski