Seting in our mobile phone can add many types of accounts, sometimes we need to launch these accounts in the program login interface, but, even if you know the login interface package name, class name, through the intent can not start, this is because of Android permissions control.
However, we also found a solution in the framework, such as we want to launch the Google account login interface, we just need to know the type of the accounts can be, like Google is com.google:
Let's take a look at how to start this interface:
private void SetupAccount (String type) {Bundle addaccountoptions = new Bundle (); Mpendingintent = Pendingintent.getbroadcast (this, 0, New Intent (), 0); Addaccountoptions.putparcelable (key_caller_identity, mpendingintent); Addaccountoptions.putboolean (Extra_has_multiple_users, Hasmultipleusers (this)); Accountmanager.get (This). AddAccount (type, NULL,/* Authtokentype */NULL,/* Requiredfeatures */addaccountoptions, NULL, mcallback, NULL /* Handler */); The public boolean hasmultipleusers (context context) {return (Usermanager) Context.getsystemservice (context.user _service). Getusers (). Size () > 1; }/** * Callback setting Google account. */private accountmanagercallback<bundle> mcallback = new Accountmanagercallback<bundle> () { @Override public void Run (accountmanagerfuture<bundle>) {try {Bundle B Undle = Future.getresult (); Intent Intent = (Intent) bundle.get (accountmanager.key_intent); if (intent! = null) {Bundle addaccountoptions = new Bundle (); Addaccountoptions.putparcelable (key_caller_identity, mpendingintent); Addaccountoptions.putboolean (Extra_has_multiple_users, Hasmultipleusers (kswarning.this) ); Intent.putextras (addaccountoptions); Startactivityforresult (Intent, 0); }} catch (OperationCanceledException e) {} catch (IOException e) { } catch (Authenticatorexception e) {}}};
We can do this by calling SetupAccount () to pass the account type in.
This code is the code in the framework, and we'll use it with a little modification. So, the framework is a treasure, many functions can be found in the framework of the solution, the code is there, see how you find out.
Above.
Call the login interface of the account type in the system