Android Question How can i get sd-card write permmision on androd 11 ?

sugemd

Member
my manifest code like this:


B4A:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
    <uses-permission
   android:name="android.permission.WRITE_EXTERNAL_STORAGE"
   android:maxSdkVersion="29" />
    )

AddPermission(android.permission.WRITE_INTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_MEDIA_STORAGE)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")

SetApplicationAttribute(android:theme, "@android:style/Theme.Translucent")
'SetApplicationAttribute(android:theme, "@android:style/Theme.White")
'End of default text.

' 28 - Non-ssl (non-https) communication is not permitted by default.
' It can be enabled in B4A v9+ by adding this line to the manifest editor:
CreateResourceFromFile(Macro, Core.NetworkClearText)

but i can't get sd-card write permission, i create path , no error happen ,but the path not exist, why?

B4A:
If File.Exists(File.DirInternal, "/Pldata") = False Then
    File.MakeDir(File.DirInternal, "Pldata")
End If
 

sugemd

Member
i use the code in the article https://www.b4x.com/android/forum/t...list-of-other-related-methods.129897/#content
and i can save file in the select path,
but another question , how can i get the select path ?
I didn't find a method in the sample code

B4A:
Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetField("processBA")
End Sub


Sub SaveFile (Source As InputStream, MimeType As String, Title As String) As ResumableSub
    Dim intent As Intent
    intent.Initialize("android.intent.action.CREATE_DOCUMENT", "")
    intent.AddCategory("android.intent.category.OPENABLE")
    intent.PutExtra("android.intent.extra.TITLE", Title)
    intent.SetType(MimeType)
    StartActivityForResult(intent)
    Wait For ion_Event (MethodName As String, Args() As Object)
    If -1 = Args(0) Then 'resultCode = RESULT_OK
        Dim result As Intent = Args(1)
        Dim jo As JavaObject = result
        Dim ctxt As JavaObject
        Dim out As OutputStream = ctxt.InitializeContext.RunMethodJO("getContentResolver", Null).RunMethod("openOutputStream", Array(jo.RunMethod("getData", Null)))
        File.Copy2(Source, out)
        out.Close
        Return True
    End If
    Return False
End Sub

Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    m_ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array(m_ion, i))
End Sub

for example , i select path "/dowload/pldata/"
but how can i get the path string in my code?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't assume that there is a path to a simple file on the file system. The user can choose to save the resource using a service such as Google Drive or any other app.

The TextEditor example extracts information when the user loads a resource: https://www.b4x.com/android/forum/t...e-and-load-external-files.132731/#post-838166
You might be able to use similar code with the value returned from jo.RunMethod("getData", Null).
 
Upvote 0
Top