- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 Intent.ACTION_GET_CONTENT
打开最近的文件。从最近的文件中选择项目会给出错误的 URI,但从文件管理器中选择相同的文件会给出可以由我的代码处理的正确 URI。
public static String getRealPathFromURI(Context context, Uri uri) {
String path;
if ("content".equals(uri.getScheme())) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
path = cursor.getString(idx);
cursor.close();
} else {
path = uri.getPath();
}
return path;
}
注意:当我从最近的文件中选择 PDF 时,uri.getPath()
的输出是 /document/...
但是从文件管理器中选择相同的文件是 .../emulated/...
。
注意从最近的文件中选择文件时的错误是
Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
最佳答案
问题是我的代码不处理 Android 的新布局存储 URI。如果你也遇到这个问题,请引用this link因为作者写了一个很棒的方法来获取每个 URI 的真实路径。
关于android - Intent.ACTION_GET_CONTENT 打开最近的文件,这给出了错误的 URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32177227/
我正在使用 ACTION_GET_CONTENT,以便用户可以选择我的其余代码可以读取和处理的文本文件。 Intent intent = new Intent(); intent.setAction(
我在使用 ACTION_GET_CONTENT 从 Downloads 目录中选择文件时遇到问题。 如果我在本地存储中的 ES 资源管理器或文件管理器中删除任何文件,在我的应用程序中打开时,这些已删除
好的,我用这个开始我的功能 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType
我在我的应用中实现了一个文件选择器,如下所示: Intent intent = new Intent(); intent.setType("*/*"); intent.setAction(Intent
Google Drive 似乎有一个响应 GET_CONTENT 操作的 Activity ,但它没有导出。 我可以在我的应用程序中使用另一种方法从云端硬盘中提取内容,而无需从 云端硬盘启动流程吗?自
我有以下 Intent : Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("text/*"); start
我正在为我的 Android 应用实现导入功能。我想让用户选择他们想要从设备上的外部存储(确切地说是下载目录)和其他在线文件存储(例如 DropBox 和 Google Drive)导入的文件。 我在
流程是: 用户需要选择要使用的文本文件以及弹出的默认 Android 资源管理器。 然后我想存储包含文件名的字符串,以实际打开文件进行读取。 我想打开该文件并将其重写为应用内部存储上的新文件。 我想从
我正在尝试打开最近的窗口,该窗口只能选择图像和 pdf Intent intent = new Intent(); intent.setType("image/*"); intent.setActio
我正在尝试将文件选择器 Intent 中的选定文件(不限于图像,它可以是任何文件)放入一个 zip 文件。我需要完整的文件路径才能执行此操作,但 Intent 仅提供 uri 路径。 我试过 .get
我有一个使用 ACTION_GET_CONTENT 的已发布应用程序 Intent 让用户选择他/她的一张照片。这是启动 Intent 的代码: Intent intent = new Intent(
我正在尝试在 android 应用程序中阅读 pdf 文件。 触发以下 Intent 以获取 URI。 Intent intent = new Intent(Intent.ACTION_GET_CON
我的问题很简单。是否可以通过 Intent.ACTION_GET_CONTENT 以某种方式传递额外的数据?其中Activity收到Intent在它的onActivityResult()能读出吗? 现
我需要完成这些步骤: 让用户选择一个文件(任何类型的文件) 获取永久引用以便稍后访问文件或复制到我的内部存储。 第一个真的很简单。使用 Intent.ACTION_GET_CONTENT 获取文件没有
我正在尝试获取用户选择的文件的路径,为结果调用 intent ACTION_GET_CONTENT。 问题是当从文件管理器中选择一个音频文件时, Intent 不返回文件的扩展名(我检查过的文件名中有
我试图只显示 MP3 文件: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("audio/mp3"); s
Web 和 stackoverflow 包含几个示例如何使用 ACTION_GET_CONTENT Intent 从另一个 Android 应用程序获取文件(例如,将其用作电子邮件附件)。但是我必须实
我正在开发一个应用程序,在此 Activity 中按下一个按钮,可以选择要上传的任何文件。文件选择器加载正确,但所有图像都无法选择(变灰)。我在 Manifest 文件中添加了 READ_EXTERN
在我的应用中,我需要从用户的库中获取音频文件。 为此,我将其称为 Intent: Intent selectIntent = new Intent(Intent.ACTION_GET_CONTENT)
作为docs说:“ACTION_GET_CONTENT 可以让用户浏览网络并下载所需的数据”。这就是我需要的,来自 Google Images。虽然,如果我使用此 Intent 的类型,应用程序会崩溃
我是一名优秀的程序员,十分优秀!