Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to open "Add a Google Account" activity using intent?

Tags:

java

android

My question is how to open "Add a Google Account" activity using intent without using AccountManager which requires the following permission:

<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />

I mean find a way to go around the following solution:

AccountManager accountMgr = AccountManager.get(context);
accountMgr.addAccount("com.google", "ah", null, new Bundle(), context, null, null);

I'll provide the solution for anyone out there searching for the solve this issue.

like image 790
moh.sukhni Avatar asked Nov 05 '13 17:11

moh.sukhni


2 Answers

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); 
}
like image 60
moh.sukhni Avatar answered Oct 20 '22 00:10

moh.sukhni


If you're searching for an adb solution, here it is:

adb shell am start -a "android.settings.ADD_ACCOUNT_SETTINGS" --esa "account_types" "com.google"
like image 29
CobaltVO Avatar answered Oct 20 '22 00:10

CobaltVO