Rename file of the Mediastore which is created by app in android 10. Working on Android API 30 but shows error in API 29

前端 未结 1 793
萌比男神i
萌比男神i 2020-11-29 14:05

Here, this renameFile(..) func is working in Android API 30. But, it is not working in Android API 29 and shows the error like :

java.lang.IllegalArgumentExceptio

1条回答
  •  离开以前
    2020-11-29 14:49

    java.lang.IllegalArgumentException: Movement of content://media/external/file/116 which isn't part of well-defined collection not allowed

    So it is for Android Q not allowed if you use the collection;

    Uri extUri = MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL);
    

    But is is allowed for a 'well-defined collection' like:

    Uri extUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
    // Use  "Pictures/MyFolder" for RELATIVE_PATH
    

    I leave it to you to find other well-defined collections.

    Why this is only for Android Q i dont know.

    You can see the message in the java file: https://android.googlesource.com/platform/packages/providers/MediaProvider/+/refs/heads/master/src/com/android/providers/media/MediaProvider.java

    Quote:

         // We only support movement under well-defined collections
            switch (match) {
                case AUDIO_MEDIA_ID:
                case VIDEO_MEDIA_ID:
                case IMAGES_MEDIA_ID:
                case DOWNLOADS_ID:
                    break;
                default:
                    throw new IllegalArgumentException("Movement of " + uri
                            + " which isn't part of well-defined collection not allowed");
            }
    

    If the rename fails use SAF (as mentioned before). How to rename a file in Android knowing only its media content Uri

    0 讨论(0)
提交回复
热议问题