Android M - GoogleAccountCredential setSelectedAccount不起作用 - 名称不能为空 [英] Android M - GoogleAccountCredential setSelectedAccount doesn't work - name must not be null
问题描述
在Android M-Preview上 GoogleAccountCredential.setSelectedAccount
似乎不起作用。
调试时,我注意到在调用该方法后, selectedAccount
和 accountName
对象的字段仍为空。
调试时可以看到我的变量 accountName
不为空或为空,我调用 .setSelectedAccountName()
,但正如您在调试窗口中看到的那样,GoogleAccountCredential中的字段仍然为null。
我认为这可能与某些权限有关?在我的Manifest中,我声明了以下权限:
< uses-permission android:name =android.permission.GET_ACCOUNTS />
< uses-permission android:name =android.permission.USE_CREDENTIALS/>
<使用权限android:name =android.permission.MANAGE_ACCOUNTS/>
我知道您获得的 GET_ACCOUNTS
权限M上免费(根据 https://developer.android.com /preview/features/runtime-permissions.html#normal ),但其他两个权限对于M-Preview是未知的。所以也许,是这样吗?
Activity.requestPermissions()
只有这样您才能与设备上的其他应用创建的帐户进行互动。
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.
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?
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.
这篇关于Android M - GoogleAccountCredential setSelectedAccount不起作用 - 名称不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!