我的问题是如何在不使用需要以下权限的AccountManager的情况下使用意图打开“添加Google帐户”活动:
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
我的意思是找到一种解决以下问题的方法:
AccountManager accountMgr = AccountManager.get(context);
accountMgr.addAccount("com.google", "ah", null, new Bundle(), context, null, null);
我将为所有寻求解决此问题的人提供解决方案。
通过在意向额外数据中提供EXTRA_ACCOUNT_TYPES来解决上述问题。并将值设置为“ com.google”以提醒活动:
public static void startAddGoogleAccountIntent(Context context)
{
Intent addAccountIntent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
addAccountIntent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[] {"com.google"});
context.startActivity(addAccountIntent);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句