Android 游标在查询时总是返回null
我正在使用意图从我的Android设备中选择一个文件。当显示选择器时,我选择Astro文件管理器,然后继续选择一个文件(本例中为视频) 我得到一个URI(Android 游标在查询时总是返回null,android,android-contentprovider,android-cursor,Android,Android Contentprovider,Android Cursor,我正在使用意图从我的Android设备中选择一个文件。当显示选择器时,我选择Astro文件管理器,然后继续选择一个文件(本例中为视频) 我得到一个URI(content://com.metago.astro.filecontent/file/file/sdcard/Download/video_video.mp4)我尝试用以下方法处理它: Cursor cursor = null; final String column = null; final String[] pr
content://com.metago.astro.filecontent/file/file/sdcard/Download/video_video.mp4
)我尝试用以下方法处理它:
Cursor cursor = null;
final String column = null;
final String[] projection = null;
try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
// Never enters here because cursor always null
L.p("Hi!");
}
} catch (Exception e) {
L.p(e.getMessage()); // Never hit
} finally {
if (cursor != null)
cursor.close();
}
然而,游标总是返回
null
。知道为什么会发生这种情况吗?也许Astro不支持OpenableColumns
。我想,至少如果你在用来“选择文件”的Intent
上有CATEGORY\u OPENABLE
,它们应该是可以打开的但我仍然得到null
。您确定这不会引发异常吗?您不会显示catch
块以及是否正在记录任何内容。是的,它为null,但不会引发异常。我已经更新了代码片段。PS谢谢你的时间。根据你的描述,这似乎是Astro中的一个bug。你可以联系他们,看看他们有什么要说的。或者,或者解决无法检索OpenableColumns
这一事实。这些仅提供显示名称和大小。对于显示名称,使用Uri
上的getlastpathsgment()
剪掉文件名,因为它们的Uri
恰好是这样工作的。