我正在尝试在gridview中显示缩略图,但我无法弄清楚如何让我的光标访问一个名为" FoMOvideos"的特定文件夹。我该怎么用 .getColumnIndex(MediaStore.Files.FileColumns.DATA 只访问外部存储空间中的一个文件夹?
private Uri getUriFromMediaStore(int position) {
//int dataIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA);
int dataIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA + "FoMOvideos");
mMediaStoreCursor.moveToPosition(position);
String dataString = mMediaStoreCursor.getString(dataIndex);
Uri mediaUri = Uri.parse("file://" + dataString);
//TODO: Figure out how to direct only to FoMO videos.
//Uri mediaUri = Uri.parse("file:///storage/emulated/0/Movies/AppVideos" + dataString);
return mediaUri;
}
private void getOnClickUri(int position) {
int mediaTypeIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE);
int dataIndex = mMediaStoreCursor.getColumnIndex(MediaStore.Files.FileColumns.DATA + "FoMOvideos");
mMediaStoreCursor.moveToPosition(position);
String dataString = mMediaStoreCursor.getString(dataIndex);
Uri mediaUri = Uri.parse("file://" + dataString);
//TODO: Figure out how to direct only to FoMO videos.
//Uri mediaUri = Uri.parse("file:///storage/emulated/0/Movies/AppVideos" + dataString);
我尝试添加" FoMOvideos"我的dataindex变量的文件夹名称,但这会导致以下错误:
03-26 19:28:43.949 16399-16399 /? E / AndroidRuntime:致命异常: 主要 处理:example.fadysi.fomoapp,PID:16399 java.lang.IllegalStateException:无法从中读取第0行,第1行 CursorWindow。确保之前正确初始化了Cursor 从中访问数据。 在android.database.CursorWindow.nativeGetString(本机方法) 在android.database.CursorWindow.getString(CursorWindow.java:438) 在android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51) 在android.database.CursorWrapper.getString(CursorWrapper.java:137) at example.fadysi.fomoapp.ThumbnailVideoPlay.MediaStoreAdapter.getUriFromMediaStore(MediaStoreAdapter.java:104) at example.fadysi.fomoapp.ThumbnailVideoPlay.MediaStoreAdapter.onBindViewHolder(MediaStoreAdapter.java:46) at example.fadysi.fomoapp.ThumbnailVideoPlay.MediaStoreAdapter.onBindViewHolder(MediaStoreAdapter.java:18) 在android.support.v7.widget.RecyclerView $ Adapter.onBindViewHolder(RecyclerView.java:6067) 在android.support.v7.widget.RecyclerView $ Adapter.bindViewHolder(RecyclerView.java:6100) 在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5282) 在android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5158) 在android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:2061) 在android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:562) 在android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408) 在android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580) 在android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170) 在android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3379) 在android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3188) 在android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3632) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) 在android.widget.FrameLayout.onLayout(FrameLayout.java:273) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.support.v4.view.ViewPager.onLayout(ViewPager.java:1799) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131) 在android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) 在android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1367) 在android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:849) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) 在android.widget.FrameLayout.onLayout(FrameLayout.java:273) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) 在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) 在android.widget.LinearLayout.onLayout(LinearLayout.java:1495) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) 在android.widget.FrameLayout.onLayout(FrameLayout.java:273) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) 在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) 在android.widget.LinearLayout.onLayout(LinearLayout.java:1495) 在android.view.View.layout(View.java:16636) 在android.view.ViewGroup.layout(ViewGroup.java:5437) 在android.widget.FrameLayout.layoutChildren(FrameLayout.j