以编程方式创建文件夹时,Media Store无法正常工作 [英] Media Store not working when folder programmatically created

查看:143
本文介绍了以编程方式创建文件夹时,Media Store无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从程序化创建的文件夹中访问 videos 但它返回游标数 0 ,什么我应该怎么做才能解决这个问题。

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();
        }


推荐答案

你应该强迫Android MediaStore 索引创建的目录。

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)));

这篇关于以编程方式创建文件夹时,Media Store无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆