我正在使用此代码创建帐户。但它抛出了安全例外。并且帐户无法创建。
instock
logcat中的错误如下所示:
public static Account getSyncAccount(Context context) {
AccountManager accountManager =(AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
Account newAccount = new Account(context.getString(R.string.app_name), context.getString(R.string.sync_account_type));
if ( null == accountManager.getPassword(newAccount) ) {
if (!accountManager.addAccountExplicitly(newAccount, "", null))
return null;
onAccountCreated(newAccount, context);
}
return newAccount;
}
AndroidManifest看起来像这样:
02-24 22:00:03.722: E/AndroidRuntime(30319): FATAL EXCEPTION: main
02-24 22:00:03.722: E/AndroidRuntime(30319): Process: com.example.yogesh.smartshoppee, PID: 30319
02-24 22:00:03.722: E/AndroidRuntime(30319): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yogesh.smartshoppee/com.example.yogesh.smartshoppee.Activity.ShoppingListActivity}: java.lang.SecurityException: uid 10176 cannot get secrets for accounts of type: Save image
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread.-wrap11(ActivityThread.java)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.os.Handler.dispatchMessage(Handler.java:102)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.os.Looper.loop(Looper.java:148)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread.main(ActivityThread.java:5443)
02-24 22:00:03.722: E/AndroidRuntime(30319): at java.lang.reflect.Method.invoke(Native Method)
02-24 22:00:03.722: E/AndroidRuntime(30319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
02-24 22:00:03.722: E/AndroidRuntime(30319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-24 22:00:03.722: E/AndroidRuntime(30319): Caused by: java.lang.SecurityException: uid 10176 cannot get secrets for accounts of type: Save image
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.os.Parcel.readException(Parcel.java:1620)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.os.Parcel.readException(Parcel.java:1573)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.accounts.IAccountManager$Stub$Proxy.getPassword(IAccountManager.java:694)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.accounts.AccountManager.getPassword(AccountManager.java:334)
02-24 22:00:03.722: E/AndroidRuntime(30319): at com.example.yogesh.smartshoppee.sync.AppSyncAdapter.getSyncAccount(AppSyncAdapter.java:190)
02-24 22:00:03.722: E/AndroidRuntime(30319): at com.example.yogesh.smartshoppee.sync.AppSyncAdapter.initializeSyncAdapter(AppSyncAdapter.java:234)
02-24 22:00:03.722: E/AndroidRuntime(30319): at com.example.yogesh.smartshoppee.Activity.ShoppingListActivity.onCreate(ShoppingListActivity.java:58)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.Activity.performCreate(Activity.java:6245)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
02-24 22:00:03.722: E/AndroidRuntime(30319): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
02-24 22:00:03.722: E/AndroidRuntime(30319): ... 9 more
我在网上查了一下却无法找到解决方案。我做错了什么?