エラー:Caused by: java.lang.SecurityException: uid xxxxx cannot explicitly add accounts of type:
エラー内容
Caused by: java.lang.SecurityException: uid 10149 cannot explicitly add accounts of type: hogehoge
エラー原因ファイル
AndroidManifest.xml抜粋 <service android:name=".AuthenticatorService" android:exported="false"> <intent-filter> <action android:name=".Authenticator" /> </intent-filter> <meta-data android:name=".Authenticator" android:resource="@xml/authenticator" /> </service>
エラー対処
自分の場合マニフェストファイルのserviceタグにエラー原因があった。
serviceタグのandroid:name属性の値は、AuthenticatorService定めているが、これはhoge.ktのAuthenticatorServiceクラスを指している。 android:name属性であれば、全てクラスを書けば良いと思っていたのでintent-filterタグやmeta-dataタグにもAuthenticatorクラスを指定していた。(AuthenticatorクラスはAbstractAccountAuthenticatorを継承したものとして自作している。)
しかし正しい記述は以下のようにしたものである。
<service android:name=".AuthenticatorService" android:exported="false"> <intent-filter> <action android:name="android.accounts.AccountAuthenticator" /> </intent-filter> <meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" /> </service>
どういうわけかまだ理解できていないが、intent-filter以下とmeta-dataのandroid:nameには"android.accounts.AccountAuthenticator"を指定するようだ。 "android.accounts.AccountAuthenticator"を指定した参考コードは以下の通り。
AccountManagerでアカウントを管理する アカウント種別の宣言