我尝试创建一个应用,打开我的Google云端硬盘,但是我收到了错误消息。我尝试了一些我在互联网上找到的解决方案,但它不起作用。首先,我尝试在gradle中更改几个版本。除了9.0.2,我尝试过使用9.0.0,8.3.0,8.4.0。
代码:
public class OpenGoogleDrive extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks
{
private static final String TAG = String.valueOf(1) ;
private static final int REQUEST_CODE_OPENER = 1;
GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_open_google_drive);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Drive.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onConnected(Bundle connectionHint) {
IntentSender intentSender = Drive.DriveApi
.newOpenFileActivityBuilder()
.setMimeType(new String[] { "text/plain", "text/html" })
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.w(TAG, "Unable to send intent", e);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
//Log.e("Connected failed", String.valueOf(mGoogleApiClient.isConnected()));
}
/*@Override
public void onResult(People.LoadPeopleResult loadPeopleResult) {
}*/
}
Gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'android'
keyPassword 'android'
storeFile file('C:/Users/MARJAN-IT/.android/debug.keystore')
storePassword 'android'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.marjan_it.upnotes"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
//compile 'com.google.android.gms:play-services:7.8.0'
//compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-plus:9.0.2'
compile 'com.google.android.gms:play-services-drive:9.0.2'
//compile 'com.google.gdata.client.contacts.ContactsService'
compile group: 'com.google.gdata', name: 'core', version: '1.47.1'
// http://mvnrepository.com/artifact/com.google.apis/google-api-services-drive
//compile group: 'com.google.apis', name: 'google-api-services-drive', version: 'v2-rev65-1.13.2-beta'
}
Error:
06-21 15:02:29.487 9494-9494/com.example.marjan_it.upnotes E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalStateException
at com.google.android.gms.common.internal.zzaa.zzai(Unknown Source)
at com.google.android.gms.drive.internal.zzu.zzoO(Unknown Source)
at com.google.android.gms.common.internal.zzd.zza(Unknown Source)
at com.google.android.gms.internal.zzod$zzc.zzrX(Unknown Source)
at com.google.android.gms.internal.zzod$zzf.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at com.google.android.gms.internal.zzpu.run(Unknown Source)
at java.lang.Thread.run(Thread.java:838)
Can you help me?
答案 0 :(得分:1)
对不起,迟到了。但我遇到了同样的问题并通过在构建GoogleApiClient时添加一个属性即addScope()来解决问题
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();