vel*_*lis 5 android accountmanager
我一直在寻找这个问题的解决方案一段时间(几天,而不是几分钟),但它很有效地避开了我.
请注意,这不是关于启动注册程序的问题.这必须自动发生,无需任何用户交互.
我想在我的自定义设备中添加一个Google帐户(其中1000个).该帐户主要用于激活设备上的Google Play商店,以便应用可以在新版本可用时进行更新.
我现有的代码(我试过的最短片段):
AccountManager mgr = AccountManager.get(this);
Account acc = new Account("email@gmail.com", "com.google");
mgr.addAccountExplicitly(acc, "password", new Bundle()));
Run Code Online (Sandbox Code Playgroud)
自然产生一个
java.lang.SecurityException: caller uid 10047 is different than the authenticator's uid
Run Code Online (Sandbox Code Playgroud)
那么我将如何实现这一目标呢?我的设备扎根,如果这是唯一的方法,那不是障碍.
警告:此解决方案效果不佳。请参阅评论以获取解释。
好吧,事实证明,这并不是一件容易解决的事情。我最终注册了一台设备,然后从中提取了用户文件。用户文件的位置:(/data/system/users/0/accounts.db如果设备上有多个用户配置文件,则最后一个目录可能会根据相关配置文件而有所不同)。
我将此文件存储到我的应用程序的资产中(gzipped,确保扩展名不是something.gz,因为它在打包过程中丢失 - 没有费心去检查原因)。
首先我检查我的用户是否已经存在:
AccountManager mgr = AccountManager.get(this);
for (Account acc: mgr.getAccountsByType("com.google")) {
if (acc.name.equalsIgnoreCase("email@gmail.com"))
return;
}
Run Code Online (Sandbox Code Playgroud)
如果是的话,我就跳过这一步。否则,我解压用户文件并覆盖现有文件(使用su)。然后我还重新启动以确保更改已注册。
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |