Media Store not working when folder programmatically created

白昼怎懂夜的黑 提交于 2019-12-17 20:32:32

问题


I am accessing videos, from programmatically created folder, using following code But it returning cursor count 0, what should I do to solve this problem.

I have tested it on some devices, this is not perfect solution. looking for better one, can anyone help me?

 String selection=MediaStore.Video.Media.DATA +" like?";
        String[] selectionArgs=new String[]{"%smartVcall%"};
        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, selection, selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");

To create folder I am using following code

 File moviesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/smartVcall");
        if (!moviesDir.exists()) {
            moviesDir.mkdirs();
        }

回答1:


You should force the Android MediaStore to index created directory.

String directoryPath = "file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/smartVcall"
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(directoryPath)));


来源:https://stackoverflow.com/questions/48934159/media-store-not-working-when-folder-programmatically-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!