Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling chart1.saveToGallery() function in Android 14 causes Mutation of _data is not allowed exception to occur #5497

Open
emadPirayesh opened this issue Nov 19, 2024 · 0 comments

Comments

@emadPirayesh
Copy link

emadPirayesh commented Nov 19, 2024

                                                                                         ```

java.lang.IllegalArgumentException: Mutation of _data is not allowed.
at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:5089)
at com.android.providers.media.MediaProvider.insert(MediaProvider.java:4973)
at android.content.ContentProvider$Transport.insert(ContentProvider.java:446)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:180)
at android.os.Binder.execTransactInternal(Binder.java:1339)
at android.os.Binder.execTransact(Binder.java:1275)

**Expected Behavior**
After searching about this issue, I removed the following code         
values.put(Images.Media.DATA, filePath); 
in chart.java line 1572 
Then the function worked and did not crash


It is said in the developer.android document :
> When you access an existing media file, you can use the value of the [DATA] column in your logic.
 That's because this value has a valid file path. However, don't assume that the file is always available. 
Be prepared to handle any file-based I/O errors that occur.
To create or update a media file, on the other hand, don't use the value of the DATA column.
Instead, use the values of the [DISPLAY_NAME]and [RELATIVE_PATH] columns.


**Possible Solution**
https://stackoverflow.com/a/61169612/7985871 
https://developer.android.com/training/data-storage/shared/media
https://gist.github.com/RikkaW/0ae7f51117768a03c6581c956d75958c

**Device 
Sumsung Galaxy S24 Ultra  
and android emulator
![crashissue](https://github.com/user-attachments/assets/aed0c5c3-03c3-458a-b231-8b638bc58bee)



@emadPirayesh emadPirayesh changed the title Calling chart1.saveToGallery() function in Android 14 causes Mutation of _data is not allowed exception to occur Calling chart1.saveToGallery() function in Android 14 causes Mutation of _data is not allowed exception to occur Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant