Alain75
Member
I write a quite simple jpg compressor : it selects one or more pictures from a folder picked by ExternalStorage in order to get read/write permission and for each file :
app crashed with message in the log saying "requires MANAGE_DOCUMENTS permission or grantUriPermission". But according to my understandings, MANAGE_DOCUMENTS is not allowed to third party apps and I am a bit lost with granturipermission...
When ContentResolver uses uri of the new file obtained with ExternalFile:
app crashes with "update not supported" even if I got read/write permission on the folder :
Is there a way to set the modification datetime or is it a lost anyway target ?
Thanks!
- Copy the selected picture in DirInternal (name = "temp") ,
- Get and store the exif informations of the file (GPSLatitudeRef, GPSLatitude, GPSLongitudeRef, GPSLongitude, DateTime and DateTimeDigitized)
- Write a new compressed file in DirInternal (name = "new")
- Set the exif informations on the new compressed file (can also set "setLastModified" but it's useless)
- Copy the compressed file as "xxx-new.jpg" in ExternalStorage folder, original file name being "xxx.jpg"
- And finally try to set "setLastModified" on the new file in ExternalStorage folder with ContentResolver
B4X:
Sub SetDateUri(fic As String, date As String)
Dim uri As Uri, cr As ContentResolver, vl As ContentValues
cr.initialize("")
uri.Parse(fic)
vl.Initialize
vl.PutString("last_modified",date)
cr.Update(uri,vl,Null,Null)
'cr.Update(sto.FindFile(sto.Root,fic.SubString(fic.LastIndexOf("%2F")+3)).Native.RunMethod("getUri",Null),vl,Null,Null)
End Sub
ContentResolver log with uri string from picked file:
copy : content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001.jpg -> temp
copy : new -> content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg
java.lang.RuntimeException: java.lang.SecurityException: Permission Denial: writing com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg from pid=463, uid=10245 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1750)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.SecurityException: Permission Denial: writing com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg from pid=463, uid=10245 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
at android.os.Parcel.createExceptionOrNull(Parcel.java:2386)
at android.os.Parcel.createException(Parcel.java:2370)
at android.os.Parcel.readException(Parcel.java:2353)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.update(ContentProviderNative.java:649)
at android.content.ContentResolver.update(ContentResolver.java:2366)
at android.content.ContentResolver.update(ContentResolver.java:2328)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Update(ContentResolverWrapper.java:110)
at b4a.jpgsizer.main._setdate2(main.java:1209)
at b4a.jpgsizer.main$ResumableSub_CompressImage.resume(main.java:760)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
... 7 more
java.lang.RuntimeException: java.lang.SecurityException: Permission Denial: writing com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg from pid=463, uid=10245 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1750)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.SecurityException: Permission Denial: writing com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg from pid=463, uid=10245 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()
at android.os.Parcel.createExceptionOrNull(Parcel.java:2386)
at android.os.Parcel.createException(Parcel.java:2370)
at android.os.Parcel.readException(Parcel.java:2353)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.update(ContentProviderNative.java:649)
at android.content.ContentResolver.update(ContentResolver.java:2366)
at android.content.ContentResolver.update(ContentResolver.java:2328)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Update(ContentResolverWrapper.java:110)
at b4a.jpgsizer.main._setdate2(main.java:1209)
at b4a.jpgsizer.main$ResumableSub_CompressImage.resume(main.java:760)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
... 7 more
When ContentResolver uses uri of the new file obtained with ExternalFile:
B4X:
Sub SetDateUri(fic As String, date As String)
Dim uri As Uri, cr As ContentResolver, vl As ContentValues
cr.initialize("")
'uri.Parse(fic)
vl.Initialize
vl.PutString("last_modified",date)
'cr.Update(uri,vl,Null,Null)
cr.Update(sto.FindFile(sto.Root,fic.SubString(fic.LastIndexOf("%2F")+3)).Native.RunMethod("getUri",Null),vl,Null,Null)
End Sub
ContentResolver Log using uri from ExternalStorage:
copy : content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001.jpg -> temp
copy : new -> content://com.android.externalstorage.documents/document/87C5-17E9%3ADCIM%2FCamera%2F0001-new.jpg
java.lang.RuntimeException: java.lang.UnsupportedOperationException: Update not supported
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1750)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.UnsupportedOperationException: Update not supported
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:174)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.update(ContentProviderNative.java:649)
at android.content.ContentResolver.update(ContentResolver.java:2366)
at android.content.ContentResolver.update(ContentResolver.java:2328)
at anywheresoftware.b4a.objects.ContentResolverWrapper.Update(ContentResolverWrapper.java:110)
at b4a.jpgsizer.main._setdateuri(main.java:1188)
at b4a.jpgsizer.main$ResumableSub_CompressImage.resume(main.java:748)
at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748)
... 7 more
Is there a way to set the modification datetime or is it a lost anyway target ?
Thanks!