One of my devices has got into the constantly asking external storage permission loop and I can see what is happening but not why
This Sub is writing the string
"(HierarchicalUri) content://com.android.externalstorage.documents/tree/3431-6431%3A"
to the "PersistantUri" file
Private Sub ion_Event (MethodName As String, Args() As Object) As Object
Log("OnActivityResult Args(0) = " & Args(0)) ' Debugging
If Args(0) = -1 Then 'resultCode = RESULT_OK
Dim i As Intent = Args(1)
Dim jo As JavaObject = i
Dim treeUri As Uri = jo.RunMethod("getData", Null)
Dim takeFlags As Int = Bit.And(i.Flags, 3)
ctxt.RunMethodJO("getContentResolver", Null).RunMethod("takePersistableUriPermission", Array(treeUri, takeFlags))
PersistantUri = treeUri 'ignore
File.WriteString(File.DirInternal, FileName, PersistantUri)
Log("PersistantUri = " & PersistantUri)
SetPickedDir
End If
Return Null
End Sub
But in this Sub the List returned from "getPersistedUriPermissions" contains
"(StringUri) content://com.android.externalstorage.documents/tree/3431-6431%3A"
Which doesn't match the string saved in the "PersistantUri" file so it tries again, and again, and again!
Public Sub SelectDir (UsePreviouslySelectedIfAvaiable As Boolean)
Log("Called SelectDir(" & UsePreviouslySelectedIfAvaiable &")") ' Debugging
Log("File " & File.DirInternal & "," & FileName & " exists = " & File.Exists(File.DirInternal, FileName)) ' Debugging
If UsePreviouslySelectedIfAvaiable And File.Exists(File.DirInternal, FileName) Then
PersistantUri = File.ReadString(File.DirInternal, FileName)
Log("Using previous selection") ' Debugging
Log("PersistantUri = " & PersistantUri) ' Debugging
Dim list As List = ctxt.RunMethodJO("getContentResolver", Null).RunMethod("getPersistedUriPermissions", Null)
If list.IsInitialized Then
Log("List is initialised") ' Debuggiing
For Each uripermission As JavaObject In list
Dim u As Uri = uripermission.RunMethod("getUri", Null)
Dim s As String = u 'ignore
Log("PersistedUriPermissions = " & s & " | Write permission = " & uripermission.RunMethod("isWritePermission", Null)) ' Debugging|
If s = PersistantUri And uripermission.RunMethod("isWritePermission", Null) = True Then
After uninstalling and reinstalling the app the List returned from "getPersistedUriPermissions" in SelectDir is
"(HierarchicalUri) content://com.android.externalstorage.documents/tree/3431-6431%3A"
which matches so all is well.
I think I will massage the returned and saved string to remove the leading parenthesized expression and see how that goes - unless a particular someone has a better suggestion!