Programatically starting the 'Add Account' activity in Android 2.2

早过忘川 提交于 2019-11-29 04:01:40
Pentium10

Check out the ACTION_ADD_ACCOUNT

startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));

Try the following:

public static void addGoogleAccount(final Activity activity) {
    final AccountManager accountMgr = AccountManager.get(activity);
    accountMgr.addAccount("com.google", "my_auth_token", null, null, activity, null, null);
}

Android Account Manager provides an API to add account. (google or other account types)

public AccountManagerFuture addAccount (String accountType, String authTokenType, String[] requiredFeatures, Bundle addAccountOptions, Activity activity, AccountManagerCallback callback, Handler handler)

http://developer.android.com/reference/android/accounts/AccountManager.html

the answer for the above question by providing EXTRA_ACCOUNT_TYPES in the intent extra data. and set the value to "com.google" in order to alert the activity:

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); }

The clue is in your shell command:

    Intent intent = new Intent();
    intent.setClassName( "com.google.android.gsf", "com.google.android.gsf.login.AccountIntroActivity" );
    context.startActivity( intent );

For recent Androids using adb you can do:

adb shell am start -a android.settings.ADD_ACCOUNT_SETTINGS \
                   -n com.android.settings/.accounts.AddAccountSettings

(You’ll still have to select what account type you’d like though)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!