简体   繁体   中英

How to access Whatsapp folder of Android 11 by using MediaStore API?

I really need your help because I'm stuck. I have already tryed all solutions I've found here in "stackoverflow" for this problem, but any of them worked for me.. I want to access External Storage folders in Android 11, How to use MediaStore for this.

If you want to read WhatsApp data,

Android 11: [EDIT]

String path=  Build.VERSION.SDK_INT<=30  ? "WhatsApp/Media/Wallpaper":"Android/media/com.whatsapp/WhatsApp/Media/Wallpaper";

Add Read Permission:

 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Add Exact path:

String path=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp <####>";

And finally read all data

private void loadData(String path) {
    File folder = new File(Environment.getExternalStorageDirectory().toString() + path);
    folder.mkdirs();


    File[] allFiles = folder.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return (name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".png"));
        }
    });
    Log.e("Datas" , allFiles.toString());
}

Other paths:

        String pathWallPaper=  "Android/media/com.whatsapp/WhatsApp/Media/Wallpaper";
        String pathGif=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Animated Gifs";
        String pathAudio=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Audio";
        String pathDocs=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Documents";
        String pathImage=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images";
        String pathStickers=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Stickers";
        String pathVideo=  "Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM