I follow the Api demos for Google Drive. Cannot create file inside public folder here
package com.google.android.gms.drive.sample.demo;
import android.os.Bundle;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.drive.Drive;
import com.google.android.gms.drive.DriveApi.ContentsResult;
import com.google.android.gms.drive.DriveApi.DriveIdResult;
import com.google.android.gms.drive.DriveFolder;
import com.google.android.gms.drive.DriveFolder.DriveFileResult;
import com.google.android.gms.drive.DriveId;
import com.google.android.gms.drive.MetadataChangeSet;
import java.lang.Override;
public class CreateFileInFolderActivity extends BaseDemoActivity {
private DriveId mFolderDriveId;
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
}
final private ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
@Override
public void onResult(DriveIdResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Cannot find DriveId. Are you authorized to view this file?");
return;
}
mFolderDriveId = result.getDriveId();
Drive.DriveApi.newContents(getGoogleApiClient())
.setResultCallback(contentsResult);
}
};
final private ResultCallback<ContentsResult> contentsResult = new
ResultCallback<ContentsResult>() {
@Override
public void onResult(ContentsResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Error while trying to create new file contents");
return;
}
DriveFolder folder = Drive.DriveApi.getFolder(getGoogleApiClient(), mFolderDriveId);
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("Sujatha.txt")
.setMimeType("text/plain")
.setStarred(true).build();
folder.createFile(getGoogleApiClient(), changeSet, result.getContents())
.setResultCallback(fileCallback);
}
};
final private ResultCallback<DriveFileResult> fileCallback = new
ResultCallback<DriveFileResult>() {
@Override
public void onResult(DriveFileResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Error while trying to create the file");
return;
}
showMessage("Created a file: " + result.getDriveFile().getDriveId());
}
};
}
my shared folder is this
as well
EXISTING_FOLDER_ID = "0B2uTE9KZI1PTRXEwQ00xRkt0Wk0"
until you can create a text file in this folder. Showing this message Cannot find DriveId. Are you authorized to view this file?, I made the folder public, and its set, which can be edited in the share options.
Any suggestions would be appreciated.
Thanks in advance
EDIT 1
- I can create files and folders on my Google drive. But not to the specific folder that I mentioned above.
source
share