如果android中的google drive不存在,如何使用google drive Api创建文件夹?
我已经在google drive中创建了一个文件夹,但每次我运行应用程序时,都会在我的google drive中创建相同的文件夹。我只是想找到一种方法来避免在google drive中创建相同的文件夹。我的代码是hear。如果有人能解决这个问题,请告诉我如果android中的google drive不存在,如何使用google drive Api创建文件夹?,android,google-drive-api,google-drive-android-api,Android,Google Drive Api,Google Drive Android Api,我已经在google drive中创建了一个文件夹,但每次我运行应用程序时,都会在我的google drive中创建相同的文件夹。我只是想找到一种方法来避免在google drive中创建相同的文件夹。我的代码是hear。如果有人能解决这个问题,请告诉我 @Override public void onConnected(Bundle bundle) { Log.i(TAG, "API client connected."); MetadataChangeSet change
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "API client connected.");
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("Testing1").build();
Drive.DriveApi.getRootFolder(mGoogleApiClient).createFolder(mGoogleApiClient,changeSet).setResultCallback(callback); }
final ResultCallback<DriveFolder.DriveFolderResult> callback = new ResultCallback<DriveFolder.DriveFolderResult>() {
@Override
public void onResult(DriveFolder.DriveFolderResult result) {
if (!result.getStatus().isSuccess()) {
Toast.makeText(getApplicationContext(), "Error while trying to create the folder", Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(getApplicationContext(), "Created a folder: " + result.getDriveFolder().getDriveId(), Toast.LENGTH_SHORT).show();
}
};
@覆盖
未连接的公共空间(捆绑包){
Log.i(标记“API客户端已连接”);
MetadataChangeSet changeSet=新建MetadataChangeSet.Builder()
.setTitle(“Testing1”).build();
Drive.DriveApi.getRootFolder(mGoogleApiClient).createFolder(mGoogleApiClient,changeSet.setResultCallback(回调);}
final ResultCallback callback=new ResultCallback(){
@凌驾
public void onResult(DriveFolder.DriveFolderResult){
如果(!result.getStatus().issucess()){
Toast.makeText(getApplicationContext(),“尝试创建文件夹时出错”,Toast.LENGTH_SHORT).show();
返回;
}
Toast.makeText(getApplicationContext(),“创建了一个文件夹:”+result.getDriveFolder().getDriveId(),Toast.LENGTH_SHORT).show();
}
};
您似乎正在onConnected中创建文件夹。每次启动应用程序时都会调用OnConnect。我会将文件夹创建代码移出OnConnect。您没有回答这个问题。