在谷歌驱动器android中的文件夹内创建一个文件夹 [英] Creating a folder inside a folder in google drive android
问题描述
我想将Google驱动器与我的应用程序集成我已经在Google Developers Console中注册了我的应用程序。我从 https://github.com/googledrive/android-demos 获取了一个示例。我能够在Google驱动器的根文件夹中创建文件,但问题是我无法在现有文件夹内创建文件或文件夹。在这种情况下,我得到了一杯烤面包找不到DriveId,您有权查看此文件吗?即我无法获得driveID
public class CreateFolderInFolderActivity extends BaseDemoActivity {
@Override
public void onConnected(Bundle connectionHint){
super.onConnected(connectionHint);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(),EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
}
final ResultCallback< DriveIdResult> idCallback = new ResultCallback< DriveIdResult>(){
@Override
public void onResult(DriveIdResult result){
if(!result.getStatus()。isSuccess()){
showMessage(result.getStatus()的toString());
showMessage(Can not find DriveId。Are you authorized to view this file?);
return;
}
DriveFolder文件夹= Drive.DriveApi
.getFolder(getGoogleApiClient(),result.getDriveId());
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle(MyNewFolder)。build();
folder.createFolder(getGoogleApiClient(),changeSet)
.setResultCallback(createFolderCallback);
}
};
final ResultCallback< DriveFolderResult> createFolderCallback = new
ResultCallback< DriveFolderResult>(){
$ b $ @Override
public void onResult(DriveFolderResult result){
if(!result.getStatus()。isSuccess ()){
showMessage(尝试创建文件夹时出现问题);
return;
}
showMessage(Folder successfully created);
}
};
}
我找不到任何适当的文件。
Plz帮助我在哪里出错或是否需要包含任何其他权限
偷看这里:在 createTree()'方法,在文件夹内创建一个文件夹。
新Google Drive Android API(GDAA)中有3个不同的驱动器ID实体
- DriveID类型的对象 - 您从方法获得并在代码中使用的对象。
- 从 encodeToString()获得的字符串并传递给 decodeFromString() - 用于在应用程序中保存(例如缓存)
- 从 getResourceId()到 fetchDriveId() - 您在文件的html地址中看到的那个。
2和3标识符都是字符串,因此可能会感到困惑。标识符2在检索驱动器ID时(通过decodeFromString())速度更快。标识符3的检索速度较慢(通过fetchDriveId()),但如果您需要在其他地方使用您的标识符(例如Apps Script),则标识符3很有用。另请参阅: SO 21800257
I want to integrate Google drive with my app I have registered my app in Google Developers Console. I got a sample from https://github.com/googledrive/android-demos .By this i am able to create a file,folder in Google drive's root folder but the problem is I couldn't create a file or folder inside an existing folder. In such case i got a toast "Cannot find DriveId. Are you authorized to view this file?" ie I cannot get the driveID
public class CreateFolderInFolderActivity extends BaseDemoActivity {
@Override
public void onConnected(Bundle connectionHint) {
super.onConnected(connectionHint);
Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FOLDER_ID)
.setResultCallback(idCallback);
}
final ResultCallback<DriveIdResult> idCallback = new ResultCallback<DriveIdResult>() {
@Override
public void onResult(DriveIdResult result) {
if (!result.getStatus().isSuccess()) {
showMessage(result.getStatus().toString());
showMessage("Cannot find DriveId. Are you authorized to view this file?");
return;
}
DriveFolder folder = Drive.DriveApi
.getFolder(getGoogleApiClient(), result.getDriveId());
MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
.setTitle("MyNewFolder").build();
folder.createFolder(getGoogleApiClient(), changeSet)
.setResultCallback(createFolderCallback);
}
};
final ResultCallback<DriveFolderResult> createFolderCallback = new
ResultCallback<DriveFolderResult>() {
@Override
public void onResult(DriveFolderResult result) {
if (!result.getStatus().isSuccess()) {
showMessage("Problem while trying to create a folder");
return;
}
showMessage("Folder successfully created");
}
};
}
I cannot find any proper documentation for this. Plz help me where i am going wrong or Whether I Have to include any other permissions
You can take a peek here: in the 'createTree()' method, there is a creation of folder within a folder.
There are 3 different drive ID entities in the new Google Drive Android API (GDAA)
- the object of type DriveID - the one you get from methods and use in your code
- a string you get from encodeToString() and pass to decodeFromString() - used to save within the app (caching for instance)
- a string you get from getResourceId() and pass to fetchDriveId() - the one you see in the html address of a file.
Both 2 and 3 identifiers are strings, so they may be confused. Identifier 2 is faster when retrieving Drive ID (via decodeFromString()). Identifier 3 is slower to retrieve (via fetchDriveId()), but usefull if you need to take your ID elsewhere (Apps Script, for instance).
Please see also: SO 21800257
这篇关于在谷歌驱动器android中的文件夹内创建一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!