0

I want to make a request for my Android application to display a Google Tasks task (in an AsyncTask).

public class TacheAsyncTask extends AsyncTask<Void, Void, String> {
private AsyncResponse delegate;
private Activity mActivity;
TacheAsyncTask(AsyncResponse asyncResponse, Activity activity) {
    this.delegate = asyncResponse;
    this.mActivity = activity;
}

@Override
protected String doInBackground(Void... params) {

    AccountManager accountManager = AccountManager.get(mActivity);
    Account myAccount = accountManager.getAccounts()[0];
}

With the AccountManager, I only get my Samsung account (length of the request = 1), so I have no access to Google Tasks.

In my Manifest :

<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android:permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.samsung.android.app.notes.READ"/>

In my build.gradle (app) :

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:28.0.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  implementation 'com.android.support:support-v4:28.0.0'
  implementation 'com.android.support:recyclerview-v7:28.0.0'
  implementation 'com.android.support:cardview-v7:28.0.0'

  implementation 'pub.devrel:easypermissions:2.0.1'

  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

  implementation 'com.google.api-client:google-api-client:1.25.0'
  implementation 'com.google.apis:google-api-services-oauth2:v1-rev155-1.25.0'
  implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
  implementation 'com.google.apis:google-api-services-tasks:v1-rev49-1.23.0'
  implementation 'com.google.api-client:google-api-client-jackson2:1.25.0'
}
Gaurav Mall
  • 2,372
  • 1
  • 17
  • 33
Pierre
  • 1
  • 1

1 Answers1

1

I am running into the same issue, and just posted a similar question on here. I suspect that it is due to this issue which affects all Android devices running Oreo. As described there you must use GoogleAuthUtil.requestGoogleAccountsAccess to get the list of Google accounts. Unfortunately that requires a non-blocking call to the service, and then using the completion of the background thread to trigger the Google account retrievals, which I am currently trying to work into my program.