Navi
Navi

Reputation: 449

Google drive as service in Android

I am trying to implement to upload some files to google drive via some service in google drive to a particular google account from multiple users of my application .How can i do it.

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();

 }

But when i am executing execute() of service i get this error:

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

Upvotes: 1

Views: 2387

Answers (2)

aaronvargas
aaronvargas

Reputation: 14142

  • You need to have the google-play-service library project (not just the jar) as a dependency

AND

  • IN the google-play-services project add the lib/google-play-services.jar to the build path.
  • Export that jar. Right-click > Build Path > Configure build path... Order and Export tab > check the google-play-services.jar
  • CLEAN Both Projects

Launch your project and it should be ok now.

Upvotes: 0

Vasile Jureschi
Vasile Jureschi

Reputation: 2249

To me it looks like you have a problem with the dependencies needed to run the sample code:

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

Have you included all the required dependencies? The Google Drive quickstart page says you need to include google-play-services.jar as a dependency https://developers.google.com/drive/quickstart-android#step_3_create_and_configure_an_android_project

Upvotes: 1

Related Questions