addAccountExplicitly throws IllegalStateException caused by Securityexception

放肆的年华 提交于 2019-12-01 09:17:47

have you tried setting permissions in the manifest, i suspect you may need this?

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

The documentation for AddAccountExplicitly say:

This method requires the caller to hold the permission AUTHENTICATE_ACCOUNTS and to have the same UID as the added account's authenticator.

The SecurityException that is thrown explains the problem, the UID of the application that is trying to add the account is different from the UID of the authenticator. In other words they are two different applications.

If you want these two to be separate applications you could make sure you share the UID between them. See the android:sharedUserId section of this page for a bit more information on how to do that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!