sorry if this is a dummy question, but I am quite new coding in Android and using the Google Drive API.
In my app, I need to create a file within a folder I previously created. At the time that the folder is created, I can only retrieve the DriveID using DriveId.encodeToString. So, in order to get the ResourceID for the creation of the file in that folder, I have implemented the following code. Although the code is working, this code never returns to the previous activity.
Could anyone help me and explain the reason? I suspect that it should be something related to the .setResultCallback.
This is how I call the activity:
Intent intent = new Intent(this, test.class);
intent.putExtra("projectFolderID", selectedProject.getpId());
intent.putExtra("FileName", LIKED_FILE_NAME);
intent.putExtra("LikedArticle", userLikes);
//startActivityForResult(intent, LIKE_FILE);
startActivity(intent);
This is the code in the activity to create the file
public class test extends BaseActivity {
private DriveId mFolderDriveId;
private DriveId projectFolderID;
private String folderResourceID;
private DriveFolder appFolder;
private String nFile;
private LikedArticles userLikes;
private boolean printed = false;
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
//Get Data from previous activity
Intent intentDisplayQuery = getIntent();
projectFolderID = DriveId.decodeFromString(intentDisplayQuery.getStringExtra("projectFolderID"));
nFile = intentDisplayQuery.getStringExtra("FileName");
userLikes = (LikedArticles) intentDisplayQuery.getSerializableExtra("LikedArticle");
//Retrieve the resourceId of the project folder from decoding Id
if (userLikes.getmLikedArticle().size()>0){
appFolder = projectFolderID.asDriveFolder();
appFolder.getMetadata(getGoogleApiClient())
.setResultCallback(metadataCallback);
}
}
final private ResultCallback<DriveResource.MetadataResult> metadataCallback = new
ResultCallback<DriveResource.MetadataResult>() {
@Override
public void onResult(DriveResource.MetadataResult metadataResult) {
if (!metadataResult.getStatus().isSuccess()) {
showMessage("Problem while retrieving files");
return;
}
Metadata mdb;
try {
mdb = metadataResult.getMetadata();
mFolderDriveId = mdb.getDriveId();
folderResourceID = mFolderDriveId.getResourceId();
/*Drive.DriveApi.fetchDriveId(getGoogleApiClient(), folderResourceID)
.setResultCallback(idCallback);*/
} finally { }
}
};
}
Thanks in advance for your help.