Call the login interface of the account type in the system

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.