我已经在google驱动器中创建了文件夹,但每次运行应用程序时,都会在我的google驱动器中创建相同的文件夹。我只想找到如何避免在谷歌驱动器中创建相同文件夹的方法。我会听到代码。如果有人能解决这个问题,请告诉我。
@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();
}
};
答案 0 :(得分:-1)
您似乎在onConnected中创建了该文件夹。每次启动应用程序时都会调用onConnected。我将文件夹创建代码移出onConnected。