简体   繁体   English

是否可以使用 MediaStore.VOLUME_EXTERNAL 获取 WhatsApp 媒体文件

[英]Is it possible to get WhatsApp media file using MediaStore.VOLUME_EXTERNAL

My app requires a feature that backups WhatsApp status, voice notes, and images.我的应用程序需要备份 WhatsApp 状态、语音笔记和图像的功能。 As you know after Android Q google enforcing to access external media files using MediaStore API.如您所知,在 Android Q 谷歌强制使用 MediaStore API 访问外部媒体文件之后。

WhatsApp also moved their file to /Android/media/com.whatsapp/WhatsApp . WhatsApp 还将他们的文件移动到/Android/media/com.whatsapp/WhatsApp I tried using MANAGE_EXTERNAL_STORAGE permission it works fine, but backing up these files is not the core functionality of the app, so I don't think google going to let me use this permission.我尝试使用MANAGE_EXTERNAL_STORAGE权限它工作正常,但备份这些文件不是应用程序的核心功能,所以我认为谷歌不会让我使用这个权限。

I wonder if there any way to read those files using MediaStore.VOLUME_EXTERNAL?我想知道是否有任何方法可以使用 MediaStore.VOLUME_EXTERNAL 读取这些文件?

I tried something like this.我试过这样的事情。 I am not sure if this is even possible.我不确定这是否可能。

val collection = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL)

val selection= (MediaStore.Files.FileColumns.MEDIA_TYPE + "="
        + MediaStore.Files.FileColumns.MEDIA_TYPE_NONE)
val selectionArgs= arrayOf("%/WhatsApp/Media/.Statuses%")
val cursor = applicationContext.contentResolver.query(
    collection, null, selection, selectionArgs, null)
debug(cursor?.columnCount)
cursor?.close()

it throws an exception.它抛出一个异常。

Caused by: android.database.sqlite.SQLiteException: no such column: media_type

Try this...试试这个...

To read whatsapp status you don't need to do more things, just changed its path.要阅读 whatsapp 状态,您不需要做更多的事情,只需更改其路径即可。

Also you don't need to use MANAGE_EXTERNAL_STORAGE permission.您也不需要使用 MANAGE_EXTERNAL_STORAGE 权限。 This can work with older permission too.这也可以使用较旧的权限。

This way I have done我这样做了

String path=Environment.getExternalStorageDirectory().getAbsolutePath()+"/Android/media/"+"com.whatsapp" + "/WhatsApp/Media/.Statuses/"

File directory = new File(wa_path);
    if (!directory.exists()) {
        directory.mkdirs();
    }
    File[] files = directory.listFiles();
    if (files != null) {
        Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
        for (int i = 0; i < files.length; i++) {
            if (!files[i].getName().equals(".nomedia")) {
                your_list.add(files[i]);
            }
        }
    }

This is working in android 11 too.这也适用于 android 11。 And I only ask for "READ_EXTERNAL_STORAGE" and "WRITE_EXTERNAL_STORAGE" like before.我只像以前一样要求“READ_EXTERNAL_STORAGE”和“WRITE_EXTERNAL_STORAGE”。

So now you need to check whether "WhatsApp" folder is available in root storage(before where it was), if not available then need to check in path I mentioned above.所以现在你需要检查“WhatsApp”文件夹是否在根存储中可用(在它之前),如果不可用则需要检查我上面提到的路径。

Let me know if you didn't understand or not works.如果您不理解或不起作用,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用PICK_ACTION和MediaStore.Audio.Media.EXTERNAL_CONTENT_URI时是否可以过滤或删除显示的结果? - Is it possible to filter or remove results shown when using PICK_ACTION and MediaStore.Audio.Media.EXTERNAL_CONTENT_URI? 如何使用 MediaStore 将媒体文件从 FirebaseStorage 下载到本地存储? - How to download a media file from FirebaseStorage to local storage using MediaStore? 如何使用 MediaStore API 以正确的文件名而不是任意名称插入媒体文件到 MediaStore? - How to insert media files to MediaStore using the MediaStore API insert with the proper file name instead of arbitrary name? 使用Android MediaStore管理媒体 - Managing media using the Android MediaStore 如何使用 mediastore 获取所有音频文件 - How to get all the audio file using mediastore 在Android中的MediaStore.Audio.Media.EXTERNAL_CONTENT_URI中插入音频文件时出现问题 - problem while inserting audio file in MediaStore.Audio.Media.EXTERNAL_CONTENT_URI in android 如何使用 Mediastore 从链接将文件保存到外部存储 - How to save file to external storage from link using Mediastore 如何在 android 工作室中使用 MediaStore Api 在 android 11 中获取特定文件夹,如 WhatsApp (.Status) 文件夹 - How to get specific folder like WhatsApp (.Status) folder in android 11 using MediaStore Api in android studio 如何使用 MediaStore.Downloads 为下载目录中的文件获取文件? - How to get a File using MediaStore.Downloads for a file in the Downloads directory? 如何在不使用 MediaStore.Images.Media.DATA 的情况下通过使用 uri 获取图像真实路径 - How to get image real path by using uri without using MediaStore.Images.Media.DATA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM