我有一个应用程序,可以在Google Drive
上创建一个带有文字的文字文件。如果我尝试从我创建该文件的设备访问Google Drive
上的word文件,那么它可以工作,一切顺利,我能够读写。但是如果我尝试使用相同的应用程序在不同的设备上使用相同的DriveId
访问同一个文件,那么我无法访问它。我在StackOverflow
上看过2个相关问题,但我无法弄清楚问题。任何帮助,将不胜感激。
这是我正在使用的GoogleApiClient连接: -
if(mGoogleApiClient == null)
{
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addScope(Drive.SCOPE_FILE)
.build();
}
mGoogleApiClient.connect();
这是程序代码: -
@Override
public void onConnected(Bundle bundle) {
msg.Log("onConnected");
msg.Log(inputText.encodeToString());
DriveFile file = Drive.DriveApi.getFile(mGoogleApiClient, inputText);
file.open(mGoogleApiClient, DriveFile.MODE_READ_ONLY, null).setResultCallback(contentsOpenedCallBack);
}
final private ResultCallback<DriveApi.DriveContentsResult> contentsOpenedCallBack = new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult driveContentsResult) {
msg.Log("onResult");
msg.Log("toString ");
if (!driveContentsResult.getStatus().isSuccess()) {
Toast.makeText(getBaseContext(), "Wrong Success", Toast.LENGTH_SHORT).show();
}
final DriveContents contents = driveContentsResult.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (IOException e) {
msg.Log(e.toString());
}
String contentsAsString = builder.toString();
try {
JSONObject json = new JSONObject(contentsAsString);
String Text = json.getString("text");
SharedPreferences sp = getSharedPreferences("Font", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("value", Text);
msg.Log(Password);
} catch (Exception e) {
msg.Log(e.toString());
}
}
};
这是错误消息: -
java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
at com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
at android.content.ContentProvider$Transport.call(ContentProvider.java:279)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
03-14 21:48:48.885 2341-3805/? E/EnterpriseContainerManager﹕ ContainerPolicy Service is not yet ready!!!
03-14 21:48:48.895 25947-25947/com.gajendraprofile.googledrivesample E/ViewRootImpl﹕ sendUserActionEvent() mView == null
03-14 21:48:50.615 9473-26051/? E/DriveAsyncService﹕ Provided DriveId is invalid.
OperationException[Status{statusCode=Provided DriveId is invalid., resolution=null}]
at com.google.android.gms.drive.api.e.d(SourceFile:331)
at com.google.android.gms.drive.api.e.a(SourceFile:632)
at com.google.android.gms.drive.api.a.ab.a(SourceFile:85)
at com.google.android.gms.drive.api.a.b.a(SourceFile:27)
at com.google.android.gms.common.service.c.onHandleIntent(SourceFile:60)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.os.HandlerThread.run(HandlerThread.java:61)
答案 0 :(得分:2)
DriveId 在其他设备上没有任何意义。如果要使用文件/文件夹,则必须使用 ResourceId 在其他设备上。这是RESTful API中的旧'id'。 DriveId特定于Google Play Services *的一个特定实例。
您还可以使用title,mime,parent等元数据搜索文件/文件夹,但是!只有DriveId和ResourceId是唯一ID,其他所有(包括标题)都不是。这意味着您可以在云端硬盘上的同一位置拥有多个同名文件/文件夹!
*)试图在SO 29030110上解释这一点。
祝你好运