我想请求我的Android应用程序显示一个Google Tasks任务(在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];
}
使用AccountManager,我只能获得我的Samsung帐户(请求的长度= 1),因此我无权访问Google任务。
在我的清单中:
<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"/>
在我的build.gradle(应用程序)中:
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'
}