Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:26:19+00:00 2026-06-12T06:26:19+00:00

After looking thru lots of pages (mostly contradict) I’m not able to write a

  • 0

After looking thru lots of pages (mostly contradict) I’m not able to write a simple Android app that does connect to Google with OAuth2:

I started with this page:

https://developers.google.com/google-apps/tasks/oauth-and-tasks-on-android#account

I did download the current libs and had to experience lots of deprecated or missing functions:

  • GoogleAccountManager is deprecated
  • HttpTransport, AndroidHttp, AccessProtectedResource, GoogleAccessProtectedResource, JacksonFactory will not be found in the current libs
  • Generation of CLIENT_ID thru Developer Console worked
  • Generation of SECRET did not work for Mobile App but is required

What is the most current description? What’s the most current demo?

Just in case – here’s what I did so far. None of the methods in processTokenReceived are part of the libs:

public class ActivityMain extends Activity implements DialogInterface.OnClickListener {

    private static final String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/drive";
    private static final String CLIENT_ID = "xxxxxxxxxxxx.apps.googleusercontent.com";

    private AccountManager accountManager;
    private Account[] accounts;
    private String authName;
    private String authToken;

    @Override
    public void onClick(final DialogInterface dialogInterface, final int item) {

        processAccountSelected(accounts[item]);
    }

    @Override
    public void onCreate(final Bundle bundle) {
        super.onCreate(bundle);

        setContentView(R.layout.activitymain);

        accountManager = AccountManager.get(this);
        accounts = accountManager.getAccountsByType("com.google");

        if (accounts == null || accounts.length == 0) {
            // TODO
        } else if (accounts.length == 1) {
            processAccountSelected(accounts[0]);
        } else if (accounts.length > 1) {
            showDialog(MyConstants.DIALOG_ACCOUNTCHOSER);
        }
    }

    @Override
    protected Dialog onCreateDialog(final int id) {
        switch (id) {
            case MyConstants.DIALOG_ACCOUNTCHOSER:
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

                String[] names = new String[accounts.length];

                for (int i = 0; i < accounts.length; i++) {
                    names[i] = accounts[i].name;
                }

                alertDialogBuilder.setItems(names, this);
                alertDialogBuilder.setTitle("Select a Google account");
                return alertDialogBuilder.create();
        }

        return null;
    }

    private void processAccountSelected(final Account account) {
        if (account != null) {
            authName = account.name.toString();
            if (!Tools.isEmpty(authName)) {
                Toast.makeText(this, authName, Toast.LENGTH_LONG).show();

                accountManager.getAuthToken(account, AUTH_TOKEN_TYPE, null, this,
                        new AccountManagerCallback<Bundle>() {

                            public void run(final AccountManagerFuture<Bundle> future) {
                                try {
                                    authToken = future.getResult().getString(
                                            AccountManager.KEY_AUTHTOKEN);
                                    processTokenReceived();
                                } catch (OperationCanceledException exception) {
                                    // TODO
                                } catch (Exception exception) {
                                    Log.d(this.getClass().getName(), exception.getMessage());
                                }
                            }
                        }, null);
            }
        }
    }

    private void processTokenReceived() {
        if (!Tools.isEmpty(authToken)) {
            HttpTransport transport = AndroidHttp.newCompatibleTransport();
            AccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
                    accessToken);
            Tasks service = new Tasks(transport, accessProtectedResource, new JacksonFactory());
            service.accessKey = CLIENT_ID;
            service.setApplicationName("Google-DriveSample/1.0");
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:26:21+00:00Added an answer on June 12, 2026 at 6:26 am

    The most recent example for using AccountManager in combination with a google-api-services library is the updated Tasks API example.GoogleAccountManager was e.g. just moved to another package.

    If you are not using a build manager like Maven that resolves missing dependencies for you, you of course have to include the google-api-java-client libraries manually, which provide HttpTransport, etc.

    For using AccountManager it is sufficient to use the Simple API Access key, that is provided in the API console. The part with a certificate fingerprint will only be relevant once Google Play Services will be available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After looking after several existing posts, I am still not able to get my
After looking around (for not terribly long I have to admit) I wonder if
After looking at RescueTime for windows/mac, it seems that there's a version for linux
After looking at several questions/answers here, I'm not seeing what I think I need.
Hmm, sounds easy enough but after looking at the ones that come with StringTemplate,
I ask this not to start anything negative. Rather, after looking at ASP.NET MVC
After looking at several options to rotate the text vertically I concluded that jangle
After looking at questions like this it doesn't make sense that my __init__(self, parrent,
After looking around for some information about managing my azure app i found csmanage
After looking (Googling) on the web for a while, I can find nothing that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.