2013-01-31 27 views
1

我想實現上傳一些文件到谷歌驅動器通過谷歌驅動器中的一些服務從我的應用程序的多個用戶的特定谷歌帳戶。我該怎麼做。谷歌驅動器作爲服務在Android

private void UploadToDrive(final String filename){ 
    final GoogleAccountCredential credential; 
    credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE); 

    Thread t = new Thread(new Runnable() { 
      @Override 
      public void run() { 
      Drive service = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential) 
      .build(); 
      try { 
       // File's binary content 
       java.io.File fileContent = new java.io.File(filename); 
       FileContent mediaContent = new FileContent("application/xml", fileContent); 
       com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File(); 
       body.setTitle(fileContent.getName()); 
       body.setMimeType("application/xml"); 
      // Log.v("GoogleVideo1",fileUri.getPath());  
       com.google.api.services.drive.model.File file = service.files().insert(body, mediaContent).execute(); 
     //  Log.v("GoogleVideo2",fileUri.getPath()); 
       if (file != null) { 
       // showToast("Photo uploaded: " + file.getTitle()); 
      //  startCameraIntent(); 
       } 
      } catch (UserRecoverableAuthIOException e) { 
       Log.v(TAG,"rECOVERABLE AUTH"); 
       e.printStackTrace(); 
//   startActivityForResult(e.getIntent(), 1); 
      } catch (IOException e) { 
      // Log.e("GoogleVideo",fileUri.getPath()); 
       System.out.println("HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII"); 
       e.printStackTrace(); 
      } 
      } 
     }); 
     t.start(); 

} 

但是當我執行服務的執行()我得到這個錯誤:

01-31 16:03:17.975: I/dalvikvm(23567): Could not find method com.google.android.gms.auth.GoogleAuthUtil.invalidateToken, referenced from method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.handleResponse 
01-31 16:03:17.975: W/dalvikvm(23567): VFY: unable to resolve static method 1536: Lcom/google/android/gms/auth/GoogleAuthUtil;.invalidateToken (Landroid/content/Context;Ljava/lang/String;)V 
01-31 16:03:17.975: D/dalvikvm(23567): VFY: replacing opcode 0x71 at 0x0015 
01-31 16:03:17.975: W/dalvikvm(23567): VFY: unable to resolve exception class 143 (Lcom/google/android/gms/auth/GooglePlayServicesAvailabilityException;) 
01-31 16:03:17.975: W/dalvikvm(23567): VFY: unable to find exception handler at addr 0x25 
01-31 16:03:17.975: W/dalvikvm(23567): VFY: rejected Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler;.intercept (Lcom/google/api/client/http/HttpRequest;)V 
01-31 16:03:17.975: W/dalvikvm(23567): VFY: rejecting opcode 0x0d at 0x0025 
01-31 16:03:17.980: W/dalvikvm(23567): VFY: rejected Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler;.intercept (Lcom/google/api/client/http/HttpRequest;)V 
01-31 16:03:17.980: W/dalvikvm(23567): Verifier rejected class Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler; 
01-31 16:03:17.980: W/dalvikvm(23567): threadid=11: thread exiting with uncaught exception (group=0x40fc92a0) 
01-31 16:03:17.995: E/AndroidRuntime(23567): FATAL EXCEPTION: Thread-2472 
01-31 16:03:17.995: E/AndroidRuntime(23567): java.lang.VerifyError: com/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential$RequestHandler 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.initialize(GoogleAccountCredential.java:124) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:109) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:404) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:328) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:449) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at com.example.googledrivetest.LocationService$1.run(LocationService.java:183) 
01-31 16:03:17.995: E/AndroidRuntime(23567): at java.lang.Thread.run(Thread.java:856) 
01-31 16:03:18.025: I/Process(23567): Sending signal. PID: 23567 SIG: 9 

回答

1

對我來說,它看起來像你有運行示例代碼所需的依賴關係的問題:

01-31 16:03:17.975: I/dalvikvm(23567): Could not find method com.google.android.gms.auth.GoogleAuthUtil.invalidateToken, referenced from method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.handleResponse 

您是否包含了所有必需的依賴關係?在谷歌驅動器快速啓動頁面提示你需要包括google-play-services.jar作爲一個依賴https://developers.google.com/drive/quickstart-android#step_3_create_and_configure_an_android_project

+0

我仍然收到此錯誤,我已經檢查了Google Drive所需的所有.jars文件.. –

+0

您是否有這個問題http://stackoverflow.com/questions/668788/android-java-lang-verifyerror? –

0
  • 你需要有google-play-service庫項目(不僅僅是JAR)作爲依賴

  • 在google-play-services項目中,將lib/google-play-services.jar添加到構建路徑。
  • 導出那個罐子。右鍵單擊>構建路徑>配置構建路徑...訂單和出口標籤>檢查google-play-services.jar
  • CLEAN兩個項目

啓動您的項目,現在應該沒問題。

相關問題