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

Categories

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

java - Internal storage folder (0) not show any files

I am working on a video player app, I am showing video folders and videos, this is working fine, But the Internal storage folder "0" did not show any files but I have around 15 video files, but the other folder working fine.

Here is my code

 private ArrayList<Videos_Models>LoadVideos(Context context, String FolderName){
        ArrayList<Videos_Models> TempList = new ArrayList<>();

        Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;



        String [] projection = {
                MediaStore.Video.Media._ID,
                MediaStore.Video.Media.DATA,
                MediaStore.Video.Media.TITLE,
                MediaStore.Video.Media.SIZE,
                MediaStore.Video.Media.DATE_ADDED,
                MediaStore.Video.Media.DURATION,
                MediaStore.Video.Media.DISPLAY_NAME,
                MediaStore.Video.Media.BUCKET_DISPLAY_NAME


        };

        String selection = MediaStore.Video.Media.DATA+" Like?";
        String  []selectionArgs = new String[]{"%" + FolderName +"%"};
        Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);

        if (cursor!= null){
            while (cursor.moveToNext()){

                try {
                String id =cursor.getString(0);
                String path =cursor.getString(1);
                String title =cursor.getString(2);
                String size =cursor.getString(3);
                String dateAdded =cursor.getString(4);
                String duration =cursor.getString(5);
                String fileName =cursor.getString(6);
                String bucket_name =cursor.getString(7);
                
                int durationa = Integer.parseInt(duration);

                String duration_formet;
                int sec = (durationa/1000)%60;
                int min = (durationa/(1000*60))%60;
                int hours = durationa/(1000*60*60);

                if (hours == 0){
                    duration_formet = String.valueOf(min).concat(":" .concat(String.format(Locale.UK, "%02d",sec)));
                }else {
                    duration_formet = String.valueOf(hours).concat(":" .concat(String.format(Locale.UK, "%02d",min).concat(":" .concat(String.format(Locale.UK, "%02d",sec)))));

                }

                Videos_Models videoFiles = new Videos_Models(id, path, title,fileName,size, dateAdded,duration_formet);

                Log.d("path", path);


               if (FolderName.endsWith(bucket_name)){
                  TempList.add(videoFiles);
               }

            }catch (Exception e){

                }

            }
            cursor.close();
        }
        return TempList;
    }

What I am doing wrong ? and how to fix this?


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

1 Answer

0 votes
by (71.8m points)

Can you check if you have this permission <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

In your manifest file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...