Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google Drive API v3:从Android内容URI获取文件ID_Android_Google Api_Google Drive Api_Android Contentresolver - Fatal编程技术网

Google Drive API v3:从Android内容URI获取文件ID

Google Drive API v3:从Android内容URI获取文件ID,android,google-api,google-drive-api,android-contentresolver,Android,Google Api,Google Drive Api,Android Contentresolver,我的Android应用程序需要从Google Drive共享用户选择的文件并获取链接。v3 Google Drive API在Android上没有提供自己的文件选择器,所以我使用的是系统文件选择器 问题是com.google.api.services.drive.drive.Permissions#create需要一个fileID作为第一个参数,而系统文件选择器给我的是一个内容:URI。如何查找与此URI对应的文件ID?当我尝试使用DocumentsContract.getDocumentId(

我的Android应用程序需要从Google Drive共享用户选择的文件并获取链接。v3 Google Drive API在Android上没有提供自己的文件选择器,所以我使用的是系统文件选择器

问题是
com.google.api.services.drive.drive.Permissions#create
需要一个fileID作为第一个参数,而系统文件选择器给我的是一个内容:URI。如何查找与此URI对应的文件ID?当我尝试使用
DocumentsContract.getDocumentId(url)
DocumentsContract.getDocumentId(url).split(“doc=encoded=”)[1]
(或ContentResolver ID列之一)作为URI to ID函数时,我得到了一个404。当我尝试时,正则表达式与任何东西都不匹配

我需要翻译的content:URI示例如下:

content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DBEskNs6jf7jS24J%2FMnNdnr7fDrih03xNetfcCUsggemjSmpiWBC5

我尝试搜索从ContentResolver获得的名称和mimetype,但这有两个问题:它需要files.metadata.readonly权限,如果同一用户驱动器的不同文件夹中有同名文件,则没有帮助。

理论上,基于Javascript的Google Picker API可以在webview中运行

更新:我发现其他尝试过这种方法的人都遇到过一些问题,比如尺寸调整以适应手机屏幕等,所以这不是一个好方法


理论上,基于Javascript的Google Picker API可以在webview中运行

更新:我发现其他尝试过这种方法的人都遇到过一些问题,比如尺寸调整以适应手机屏幕等,所以这不是一个好方法


Google Picker API不是Google Drive API的一部分。它是一个单独的API,您可以也应该使用它。请参阅Google Picker API不是Google Drive API的一部分。它是一个单独的API,您可以也应该使用它。根据顶部的说明,请注意picker是用HTML和JavaScript编写的,不适用于Android。我甚至认为在我的Android应用程序中如何使用它?我原以为在WebView中启动并不困难,但我发现其他人在使用这种方法时存在大小问题。我将编辑我的答案。根据顶部的注释,该选择器是用HTML和JavaScript编写的,不适用于Android。我甚至认为在我的Android应用程序中如何使用它?我原以为在WebView中启动并不困难,但我发现其他人在使用这种方法时存在大小问题。我将编辑我的答案。