external file path?

phj

New member
Joined
Feb 2, 2020
Messages
8
a.png


I want read file in red circle.

I tried "cerberus://external/a.txt"

but wrong.

Where is the right path?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,815
Can of worms....

Internal refers to the sandboxed internal storage of that specific app.
External is an area for your app that is accessable by other apps.
Please read into this on the Android developer docs.

With both filepaths you can not browse in CX through all directories on your phone like you want to.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
535
Why do you want to open this file? Maybe there is a different way to achieve what you are after.
 

phj

New member
Joined
Feb 2, 2020
Messages
8
Can of worms....

Internal refers to the sandboxed internal storage of that specific app.
External is an area for your app that is accessable by other apps.
Please read into this on the Android developer docs.

With both filepaths you can not browse in CX through all directories on your phone like you want to.
Thank you MikeHart.

I'm Understand.

I have old project using "Monkey-x"

code are
------------------------------
Field DATAPATH:String = "Z:/Project/tile/"

Method OnCreate:Int()
#If TARGET="android"
DATAPATH = "monkey://external/tile/"
#Endif
------------------------------------------------------------
It is possible.

However not possible in "Cerberus-x"

I have to use a file in two apps at the same time.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,815
I would be surprised if it is not working anymore. The only thing that has changed regarding file pathsin CX is thst you have to replace monkey with cerberus. You can do yourself a file compare. These are the only changes i think.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,815
Btw. Your code example is different from a text file inside the root folder of your Android phone.
 

phj

New member
Joined
Feb 2, 2020
Messages
8
I would be surprised if it is not working anymore. The only thing that has changed regarding file pathsin CX is thst you have to replace monkey with cerberus. You can do yourself a file compare. These are the only changes i think.

I searched for advice.

ooooooops!!
solved!!
Turn on storage for app permissions.

path are

#If TARGET="android"
DATAPATH = "/mnt/sdcard/Download/"
#Endif
Local file:= FileStream.Open(DATAPATH + "b.txt", "r")

succesded!!

Thank you for helping!!!!!!!

I'm making a tile editor ^^
Screenshot_20200217-132424[1].jpg
 
Last edited:

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
Turn on storage for app permissions.
How did you turn permission on? I would like to store things on my Android phone's sd card like a Nintendo cartridge.
 

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
The permissions seem to be already in there? Where do you need to enable it?
Maybe I need to find the SD card path on my device, I know they might be different on different brands and models.

Screenshot 2020-07-03 at 08.02.48.png
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,815
Look into resource paths in the docs. Use external for the SD card.
 

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
Do anyone know why this code acts like it does?

After trying a lot of different paths finally I found something that works on my Android phone. I'm so happy about that!
But, why does it access the internal memory instead of the sd card?
code_language.cerberus:
Strict
Import mojo
Import brl

Function Main:Int()
    New myClass
    Return 0
End

Class myClass Extends App

    Field so:String[]

    ' -----------------------------------------------------------------
 
    Method OnCreate:Int()
        SetUpdateRate 60
      
        Local s:String
        s = "brian~nJohn3~nPeter"
      
        ' Local fw:= FileStream.Open("test1.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://data/test2.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://internal/test3.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://external/test4.txt","w") 
        Local fw := FileStream.Open("/mnt/sdcard//" + "b.txt", "w")

        If fw <> Null
            Print "File open to write"
            fw.WriteString(s)
            fw.Close()
        Else
            Print "File not open to write" 
        Endif
        
        ' Local fr := FileStream.Open("test1.txt","r")
        ' Local fr := FileStream.Open("cerberus://data/test2.txt","r")
        ' Local fr := FileStream.Open("cerberus://internal/test3.txt","r")
        ' Local fr := FileStream.Open("cerberus://external/test4.txt","r")
        Local fr := FileStream.Open("/mnt/sdcard//" + "b.txt", "r") ' internal phone (set storageenable on app)
      
        If fr <> Null
            Print "File open to read"
            Local s2:String = fr.ReadString()
            fr.Close()
            Print ("------------------")
            Print ("s2="+s2)
            Print ("------------------")
          
            so = s2.Split("~n")
            Print ("Count="+so.Length())
        Else
            Print "File not open to read" 
        Endif
        Return 0
    End
    
    ' -----------------------------------------------------------------
 
    Method OnUpdate:Int()
        Return 0
    End
    
    ' -----------------------------------------------------------------
 
    Method OnRender:Int()
        Cls 0,0,128
        SetColor 128,128,128
        PushMatrix
        Translate DeviceWidth()/2,DeviceHeight()/2
        Scale 2.0,2.0
        For Local y:Int = 1 To so.Length()
            DrawText so[y-1], 0, 0+y*20, .5, .5
        Next
        PopMatrix
        Return 0
    End
    
    ' -----------------------------------------------------------------
    
End
 

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
I forgot to say that have to do this before file access works at all. I was struggling with this for quite some time before I found this out (follow each step image 1 - 4).

1.jpg
 

Attachments

  • 2.jpg
    2.jpg
    1.4 MB · Views: 40
  • 3.jpg
    3.jpg
    2.9 MB · Views: 45
  • 4.jpg
    4.jpg
    1.8 MB · Views: 46

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
After hours gf Googling and testing I found out that on my Android 7 phone
these are the only paths that works :

Is there a command that lists available paths on any device and spits out the strings that works?

/mnt/sdcard//
/storage/emulated/0//

Sadly they are the same (internal memory)
I've found no working path for the external SD card.

code_language.cerberus:
Strict
Import mojo
Import brl

Function Main:Int()
    New myClass
    Return 0
End

Class myClass Extends App

    Field so:String[]

    ' -----------------------------------------------------------------
 
    Method OnCreate:Int()
        SetUpdateRate 60
      
        Local s:String
        s = "brian~nJohn3~nPeter"
      
        ' Local fw:= FileStream.Open("test1.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://data/test2.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://internal/test3.txt","w") 
        ' Local fw:= FileStream.Open("cerberus://external/test4.txt","w") 
        
        ' Local fw := FileStream.Open("/mnt/sdcard//" + "b.txt", "w")
          Local fw := FileStream.Open("/storage/emulated/0//" + "b.txt", "w") 'or / at end (not wo / i think)
    
        If fw <> Null
            Print "File open to write"
            fw.WriteString(s)
            fw.Close()
        Else
            Print "File not open to write" 
        Endif

        
        ' Local fr := FileStream.Open("test1.txt","r")
        ' Local fr := FileStream.Open("cerberus://data/test2.txt","r")
        ' Local fr := FileStream.Open("cerberus://internal/test3.txt","r")
        ' Local fr := FileStream.Open("cerberus://external/test4.txt","r")
        ' Local fr := FileStream.Open("/mnt/sdcard//" + "b.txt", "r") ' internal phone (set storageenable on app)
          Local fr := FileStream.Open("/mnt/sdcard//" + "b.txt", "r") ' internal phone (set storageenable on app)
      
        If fr <> Null
            Print "File open to read"
            Local s2:String = fr.ReadString()
            fr.Close()
            Print ("------------------")
            Print ("s2="+s2)
            Print ("------------------")
          
            so = s2.Split("~n")
            Print ("Count="+so.Length())
        Else
            Print "File not open to read" 
        Endif
        Return 0
    End
    
    ' -----------------------------------------------------------------
 
    Method OnUpdate:Int()
        Return 0
    End
    
    ' -----------------------------------------------------------------
 
    Method OnRender:Int()
        Cls 0,0,128
        SetColor 128,128,128
        PushMatrix
        Translate DeviceWidth()/2,DeviceHeight()/2
        Scale 2.0,2.0
        For Local y:Int = 1 To so.Length()
            DrawText so[y-1], 0, 0+y*20, .5, .5
        Next
        PopMatrix
        Return 0
    End
    
    ' -----------------------------------------------------------------
    
End
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
2,815
Since Android 10, Google disabled the access to the SD card with the regular API. From what I saw today, you would have to do some magic tricks to do it.
 

Jimmy

New member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
569
If Google closed up the SD card access for "programmatic saving" I'm thinking; maybe they want everyone to use manual
saving techniques to reach SD card, things like share / intents (and hava a file option in there).

So what about creating an Android sharing/intent function that allows the user to choose the storage card manually?
Would it be hard to make?
 
Top Bottom