如何使用intent打开"添加Google帐户"活动?

moh*_*hni 6 java android

我的问题是如何使用intent打开"添加Google帐户"活动而不使用需要以下权限的AccountManager:

<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
Run Code Online (Sandbox Code Playgroud)

我的意思是找到解决以下解决方案的方法:

AccountManager accountMgr = AccountManager.get(context);
accountMgr.addAccount("com.google", "ah", null, new Bundle(), context, null, null);
Run Code Online (Sandbox Code Playgroud)

我会为那里寻找解决这个问题的人提供解决方案.

moh*_*hni 16

通过在intent额外数据中提供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); 
}
Run Code Online (Sandbox Code Playgroud)