我在我的项目中使用了新的google drive android api。顺便说一句,我只能获得我创建的文件和文件夹 如果我在其他设备(或者是drive.google.com网站自己)中创建了文件夹和文件,我就无法保存文件和文件夹。
请检查我的代码
public void loadRootFile()
{
constant.showProgress(getActivity(), "Loading...");
DriveFolder folder = Drive.DriveApi.getRootFolder(mGoogleApiClient);
folder.listChildren(mGoogleApiClient)
.setResultCallback(metadataResult);
Drive.DriveApi.requestSync(mGoogleApiClient)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status result) {
if (!result.isSuccess()) {
// Sync not ok
showMessage("Sync error");
return;
}
}
});
}
final private ResultCallback<MetadataBufferResult> metadataResult = new
ResultCallback<MetadataBufferResult>() {
@Override
public void onResult(MetadataBufferResult result) {
vGoogleList.onRefreshComplete();
constant.hideProgress();
if (!result.getStatus().isSuccess()) {
showMessage("Problem while retrieving files");
return;
}
mGoogleList = new ArrayList<SCGoogleDrive>();
MetadataBuffer list = result.getMetadataBuffer();
for(int i=0;i<list.getCount();i++)
{
if(!list.get(i).getTitle().equals(""))
{
SCGoogleDrive item = new SCGoogleDrive(list.get(i), false);
mGoogleList.add(item);
}
}
showFiles(false);
}
};
@Override
public void onResume() {
super.onResume();
constant.showProgress(mActivity, "Loading...");
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addApi(Drive.API)
.addApi(Plus.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
@Override
public void onPause() {
if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}
super.onPause();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
constant.hideProgress();
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), getActivity(), 0).show();
return;
}
try {
result.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
constant.hideProgress();
showMessage("API client connected.");
if(mIsLogout)
{
logoutToGoogle();
}else
{
loadRootFile();
constant.gGoogleLogin = true;
mActivity.loginState();
saveLoginState();
}
}
@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
constant.hideProgress();
showMessage("GoogleApiClient connection suspended");
}
答案 0 :(得分:0)
看看这一行:
.addScope(Drive.SCOPE_FILE)
它指定了Google云端硬盘Android API(GDAA)中唯一可用的范围。它表示只有这个(Android)应用程序创建的文件/文件夹可见。