1

I am using android-demos for implementing Google Drive integration in android. I successfully created a file in google drive. Now i want to delete that newly created file. I found the reference for this through https://developers.google.com/drive/v2/reference/files/delete Now files() method in this link is not found in Drive.

private static void deleteFile(Drive service, String fileId) { try { service.files().delete(fileId).execute(); } catch (IOException e) { System.out.println("An error occurred: " + e); } }

Now please tell me how to delete file from Google Drive. I did research on this but found no solution. Some says use previous api of Google Drive. But that is obsolete now. Now Goole uses V2 for Drive.

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
bimal chawla
  • 447
  • 1
  • 7
  • 21

3 Answers3

3

Last time I checked, there is no delete in GDAA. See How to delete a file on google drive using Google Drive Android API

You can either wait for it to be implemented, or use the REST API https://developers.google.com/drive/v2/reference/files/delete

I suspect you are confusing two different APIs. GDAA is a purely local API, ie. your app is communicating with the Android Drive app. With the REST API, your app is talking over http to the Google Drive servers. Your app can use either, or a mixture of both (although you need to be pretty desparate to do that).

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • i refered the link you provided. I also put this link in my question. I already gone through this link. here a method ..... service().files()......here files() is not found in Drive service. That's why i asked the question. – bimal chawla Aug 13 '14 at 11:22
  • make sure you are using the correct Java SDK. remember the SDK for GDAA is different to the SDK for REST. For something as simple as deleting, I wouldn't bother with the sDK. Simply call http DELETE https://www.googleapis.com/drive/v2/files/{fileId}. of course you'll need to ensure you have an OAuth2 access token. – pinoyyid Aug 13 '14 at 14:39
0

Deleting files from Google drive using core API is not yet supported. So you must use Restful API calls. To do restful API calls you need to add following jars to your lib folder

google-api-client-1.19.1.jar
google-api-client-android-1.19.1.jar
google-api-services-drive-v2-rev158-1.19.1.jar
google-http-client-1.19.0.jar
google-http-client-android-1.19.0.jar
google-http-client-gson-1.19.0.jar
google-oauth-client-1.19.0.jar
gson-2.1.jar
jsr305-1.3.9.jar

now you can do restful API call withing core API calls as follows

    com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential crd = GoogleAccountCredential
                .usingOAuth2(
                        ctx,
                        Arrays.asList(com.google.api.services.drive.DriveScopes.DRIVE_FILE));
        crd.setSelectedAccountName(email);
        _drvSvc = new com.google.api.services.drive.Drive.Builder(
                AndroidHttp.newCompatibleTransport(), new GsonFactory(), crd).setApplicationName("SmsAndCallLogBackup")
                .build();

remember i connected to Google drive using core API. and for deleting only I am using restful API

following method is used to delete file from Google drive

public void delete(DriveId dId) {
        try {
            String fileID = dId.getResourceId();
            if (fileID != null)
                _drvSvc.files().delete(fileID).execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

call this method in async task otherwise it gives error it will work definitely

Flexo
  • 87,323
  • 22
  • 191
  • 272
Amol Suryawanshi
  • 2,108
  • 21
  • 29
0

I have done it successfull **

private GoogleApiClient api;

**

   public void Update(DriveId dId) {
    try {
        DriveFile sumFile = dId.asDriveFile();
        com.google.android.gms.common.api.Status deleteStatus =
                sumFile.delete(api).await();
        if (!deleteStatus.isSuccess()) {
            Log.e(TAG, "Unable to delete app data.");

        } else {
            // Remove stored DriveId.
            preferences_driverId.edit().remove("drive_id").apply();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
Sunil Chaudhary
  • 1,221
  • 12
  • 25