rig*_*roo 7 permissions android android-account android-securityexception android-6.0-marshmallow
我有一个使用Android AccountManager(包名:com.mycompany.accounts)的应用程序,它将帐户添加到设备并提供登录屏幕.我有另一个应用程序(com.mycomp.actualapp),它使用第一个应用程序添加/删除帐户.
我可以使用清单中的以下权限在Pre Marshmallow设备上成功添加和删除帐户:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
Run Code Online (Sandbox Code Playgroud)
使用sdk 22进行编译并使用sdk 22进行编译时,应自动授予这些权限.以下代码:
accountManager.removeAccount(getAccount(), activity, new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
try {
Bundle bundle = accountManagerFuture.getResult();
boolean success = bundle.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
if (success) {
Toast.makeText(activity, activity.getString(R.string.successfully_loggedout), Toast.LENGTH_LONG).show();
afterLogoutSuccess(activity);
} else {
Toast.makeText(activity.getApplicationContext(), activity.getString(R.string.failed_to_logout), Toast.LENGTH_LONG).show();
}
onLogoutListener.onLogoutFinished(success);
return;
} catch (OperationCanceledException e) {
Log.e(TAG,"Operation cancelled exception:", e);
} catch (IOException e) {
Log.e(TAG, "IOException:", e);
} catch (AuthenticatorException e) {
Log.e(TAG, "AuthenticatorException:", e);
}
onLogoutListener.onLogoutFinished(false);
}
}, null);
Run Code Online (Sandbox Code Playgroud)
失败,出现以下异常:
java.lang.SecurityException: uid 10057 cannot remove accounts of type: com.mycompany.accounts
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.accounts.IAccountManager$Stub$Proxy.removeAccount(IAccountManager.java:897)
at android.accounts.AccountManager$7.doWork(AccountManager.java:900)
at android.accounts.AccountManager$AmsTask.start(AccountManager.java:1888)
at android.accounts.AccountManager.removeAccount(AccountManager.java:897)
at com.mycomp.actualapp.utils.LoginHelper$4.doInBackground(LoginHelper.java:282)
at com.mycomp.actualapputils.LoginHelper$4.doInBackground(LoginHelper.java:242)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,这个代码在Pre Marshmallow设备上运行正常,没有任何问题.
在旁注中,我注意到使用sdk 22进行编译并且定位22:转到"设置>应用程序>我的应用程序(com.mycomp.actualapp)>权限"我只看到两个权限,"电话""存储".
我注意到用sdk 23编译并且目标23:我看到三个权限,"电话","存储"和"联系人".
我尝试过以下方法:
切换到使用sdk 23编译 - 在应用程序设置中授予所有权限,再次尝试删除帐户.仍然失败,同样的例外.
使用22进行编译并将以下权限添加到清单中.确保授予所有权限.仍然失败,同样的例外:
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
Run Code Online (Sandbox Code Playgroud)
我可以在没有其他权限授予的情况下获取用户帐户用户名和令牌,但删除帐户不起作用.我真的很感激任何帮助!
我知道现在回答已经晚了,但我想我会分享我的发现,以防其他人遇到同样的情况。
我将我的构建升级为使用 23 而不是 22 进行构建,因为我无法在 22 上解决它。然后,在尝试对它们执行任何操作之前, 我在运行时明确请求 GET_ACCOUNTS 的权限。https://developer.android.com/training/permissions/requesting.html https://developer.android.com/reference/android/Manifest.permission.html#GET_ACCOUNTS
使用 23 进行编译的更多信息:如果应用程序共享管理帐户的身份验证器的签名,则无需请求许可。在这种情况下,我的签名不匹配,所以我确实需要请求它。如果您在应用程序中创建一个帐户以在应用程序中使用,则无需在运行时请求权限。
| 归档时间: |
|
| 查看次数: |
2548 次 |
| 最近记录: |