无法从2个不同的设备访问谷歌驱动器 [英] Cannot access Google Drive from 2 different device

查看:421
本文介绍了无法从2个不同的设备访问谷歌驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了一些文字上的谷歌硬盘 A word文件的应用程序。如果我尝试访问Word文件的谷歌硬盘从在我所创建的文件,然后它的工作原理,一切事情会顺利,我可以能够将设备阅读与写作。但如果我尝试用相同的应用程序具有相同驱动器Id 来访问不同设备上的同一个文件,那么我不能访问它。我看到的计算器 2的相关问题,但我不能找出问题。任何帮助将是AP preciated。

这是我使用的GoogleApiClient连接: -

 如果(mGoogleApiClient == NULL)
    {
        mGoogleApiClient =新GoogleApiClient.Builder(本)
                .addApi(Drive.API)
                .addConnectionCallbacks(本)
                .addOnConnectionFailedListener(本)
                .addScope(Drive.SCOPE_FILE)
                。建立();
    }
    mGoogleApiClient.connect();

这是程序code: -

  @覆盖
公共无效onConnected(束束){
    msg.Log(onConnected);            msg.Log(inputText.en codeToString());
            DriveFile文件= Drive.DriveApi.getFile(mGoogleApiClient,inputText的);
            file.open(mGoogleApiClient,DriveFile.MODE_READ_ONLY,NULL).setResultCallback(contentsOpenedCallBack);
}最后的私人ResultCallback< D​​riveApi.DriveContentsResult> contentsOpenedCallBack =新ResultCallback< D​​riveApi.DriveContentsResult>(){
    @覆盖
    公共无效onResult(DriveApi.DriveContentsResult driveContentsResult){        msg.Log(onResult);
        msg.Log(的toString);
        如果(!driveContentsResult.getStatus()。isSuccess()){
            Toast.makeText(getBaseContext(),错成功,Toast.LENGTH_SHORT).show();        }            最后DriveContents内容= driveContentsResult.getDriveContents();
                    读者的BufferedReader =新的BufferedReader(新的InputStreamReader(contents.getInputStream()));
                    StringBuilder的建设者=新的StringBuilder();
                    串线;                    尝试{
                        而((行= reader.readLine())!= NULL){
                            builder.append(线);
                        }
                    }赶上(IOException异常五){
                        msg.Log(e.toString());
                    }                    串contentsAsString = builder.toString();                    尝试{
                        JSONObject的JSON =新的JSONObject(contentsAsString);                        字符串文本= json.getString(文字);
                        共享preferences SP = getShared preferences(字体,Context.MODE_PRIVATE);
                        共享preferences.Editor编辑= sp.edit();
                        editor.putString(价值,文本);
                        msg.Log(密码);
                    }赶上(例外五){
                        msg.Log(e.toString());
                    }        }};

这是错误消息: -

  java.lang.SecurityException异常:权限拒绝:获取/用户设定的设置要求为用户-2运行,但是从用户调用0;这需要android.permission.INTERACT_ACROSS_USERS_FULL
        在com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:13140)
        在android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2038)
        在com.android.providers.settings.SettingsProvider.callFromPackage(SettingsProvider.java:607)
        在android.content.ContentProvider $ Transport.call(ContentProvider.java:279)
        在android.content.ContentProviderNative.onTransact(ContentProviderNative.java:273)
        在android.os.Binder.execTransact(Binder.java:388)
        在dalvik.system.NativeStart.run(本机方法)
03-14 21:48:48.885 2341-3805 /? E / EnterpriseContainerManager:ContainerPolicy服务还没有准备好!
03-14 21:48:48.895 25947-25947 / com.gajendraprofile.googledrivesample E / ViewRootImpl:sendUserActionEvent()== MView的空
03-14 21:48:50.615 9473-26051 /? E / DriveAsyncService:提供驱动器Id是无效的。
OperationException [状态{状态code =提供驱动器Id是无效的,分辨率= NULL}]
        在com.google.android.gms.drive.api.e.d(的SourceFile:331)
        在com.google.android.gms.drive.api.e.a(的SourceFile:632)
        在com.google.android.gms.drive.api.a.ab.a(的SourceFile:85)
        在com.google.android.gms.drive.api.a.b.a(的SourceFile:27)
        在com.google.android.gms.common.service.c.onHandleIntent(的SourceFile:60)
        在android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:65)
        在android.os.Handler.dispatchMessage(Handler.java:99)
        在android.os.Looper.loop(Looper.java:176)
        在android.os.HandlerThread.run(HandlerThread.java:61)


解决方案

驱动器Id 的手段,以不同的设备上什么都没有。如果你想用一个文件/文件夹的工作,不同的设备上,你必须使用的 RESOURCEID 的。这是从REST风格的API旧的'身份证'。驱动器Id是针对一个特定实例的谷歌游戏服务*。

您还可以搜索使用类似的标题,哑剧,父母,......但元数据文件/文件夹!只有驱动器Id和RESOURCEID是唯一的ID,其他的一切(包括标题)不是。这意味着你可以有多个同名的文件/文件夹在驱动器相同的位置!

*)没有试图解释这对<一个href=\"http://stackoverflow.com/questions/29030110/cannot-get-folderid-that-i-just-created-on-google-drive\">SO 29030110 。

好运

I have an app which creates a word file on the Google Drive with some text. If I try to access the word file on the Google Drive from the device In which I have created that file, then it works and everything thing goes smooth, and I can able to read and write. But If I try to access the same file with the same DriveId on the different device with the same app, then I can't access it. I have seen 2 related questions on the StackOverflow but I can't figure out the problem. Any help would be appreciated.

This is the GoogleApiClient Connection I am using:-

    if(mGoogleApiClient == null)
    {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Drive.API)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addScope(Drive.SCOPE_FILE)
                .build();
    }
    mGoogleApiClient.connect();

This is the program code:-

@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());
                    }

        }

};

This is the error message:-

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)

解决方案

DriveId means nothing on a different device. If you want to work with a file/folder, on a different device you have to use the ResourceId. That's the old 'id' from RESTful API. DriveId is specific to one particular instance of Google Play Services*.

You can also search for files/folders using metadata like title, mime, parent, ... but! Only DriveId and ResourceId are unique IDs, everything else (including title) is not. That means you can have multiple files / folders of the same name in the same location on the Drive !

*) There is an attempt to explain this on SO 29030110 .

Good Luck

这篇关于无法从2个不同的设备访问谷歌驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆