Android Question Writing to SD card

FFMan

Member
Licensed User
I am trying to write to the sd card in an app and get a permissions error.

I have found a number of posts about this not being possible from 4.1 or thereabouts, but all the posts and comments seemed quite old.

Is this an accepted issue or is there a work around.
 

FFMan

Member
Licensed User
I have this





<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />



i'll try what you suggest
 
Upvote 0

ivan.tellez

Active Member
Licensed User
I have found a number of posts about this not being possible from 4.1

That is a security feature on android API 19+, the app can only write to the to its own application-specific directories on external storage.

Real work arounds will only work with root
 
Upvote 0

FFMan

Member
Licensed User
So I followed the post and found the code

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array(Null))
   For Each p As Object In paths
     Log(p)
   Next
End Sub

Sub GetContext As JavaObject
  Return GetBA.GetField("context")
End Sub

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

but it doesn't compile with

got error when running the code at post #9. What's wrong?

Parsing code. 0.00
Compiling code. Error
Error compiling program.
Error description: 'as' expected.
Occurred on line: 28
Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array(Null))
Word: (

so I founnd a correction mentioned

Change Array to Array As Object​

but I can't make any variation on the syntax compile

Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array(Null) as object)
Dim paths() As Object = GetContext.RunMethod("getExternalFilesDirs", Array as object)

can someone point out my error please ?

thanks
 
Upvote 0
Top