Java – Google Drive Android API – Invalid DriveId and Null ResourceId

Google Drive Android API – Invalid DriveId and Null ResourceId… here is a solution to the problem.

Google Drive Android API – Invalid DriveId and Null ResourceId

I’ve struggled with this code all day but with bad luck. I started following this code Sample from Google.

The problem is that the folder is created successfully, but in onResult() I always get an invalid or incomplete DriveId or resourceId. This means that I can’t create files in the folder I created. This is the code I’m using :

public class CreateFolderActivity extends BaseDemoActivity {

public void onConnected(Bundle connectionHint) {
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            getGoogleApiClient(), changeSet).setResultCallback(callback);

final ResultCallback<DriveFolderResult> callback = new ResultCallback<DriveFolderResult>() {
    public void onResult(DriveFolderResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Error while trying to create the folder");

 this value is always invalid with ending == operators
        Log.d("DRIVEID", "Created a folder: " + result.getDriveFolder().getDriveId());

Whenever I run this code, I get the following incomplete id:


I don’t know what’s going on here!

I googled and read about adding listeners to listen for completion events, but none of them seem to work.

I’ve seen almost similar issues on SO, but none of them worked for me.

I manually copied the FolderId through the browser after the app was created and then pasted into my android code, and the app successfully created a file. But that’s not how things are supposed to work.

Should I wait for the sync to complete? If yes, what to do?

Thanks in advance!


The answer to your question may be found The DriveId you get is fine, but you shouldn’t deal with it directly. It is a “preliminary” DriveId that changes after the object is committed (see again SO 22874657 )。 You can test it and compare the DriveId you get with the DriveId you will get in onCompletion.

This is just one of the side effects of GDAA logic, which insulates you from online/offline network states, which can cause unpredictable delays. You just need to rely on callbacks.

But to my surprise, you can’t immediately use this “preliminary” DriveId (if it’s a folder) as the parent of another object (folder/file). I’ve never experienced passing a ‘preliminary’ DriveId to another GDAA method at once.
The situation with ResourceId is different. That one is secondary in GDAA and is only used when you leave the device. GDAA does not know about the object until it is submitted (uploaded).

I used similar logic in this demo (see the MainActivity.createTree() method). You are welcome to dig deeper.

SO Related issues are discussed in 34318220.

Good luck

Related Problems and Solutions