Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

java - Media Store not working when folder programmatically created

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();
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...