Hi
when I try to read some files on android, or get its name with getrawfolderfilename(), it's not possible, the file doesn't appear and I can't read them (with opentoread).
On android, I can open external images (png, jpg) or sound (wav, mp3) from the internal disk (from "/sdcard/Documents/"), but not : .txt, .obj, .dae or other kind of file.
Do you know how I can do that ?
// Project: readexternal
// Created: 2023-11-18
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "readexternal" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
permission$ = "WriteExternal"
if ( CheckPermission( permission$ ) <= 0 )
RequestPermission( permission$ )
while( CheckPermission( permission$ ) = 1 )
Sync()
endwhile
endif
type tFolder
listfile as string[]
Endtype
global dim listfile[] as string
global dim listFolder[] as tFolder
if GetDeviceBaseName() ="android"
// don't show the file : .txt, .obj... only images png, jpg
ProcessFiles("/sdcard/Documents/myfolder")
else
ProcessFiles(GetDocumentsPath()+"/myfolder")
endif
// test to read a file named "test.txt" on android in /sdcard/Documents/myfolder/ it doesn't work.
f = opentoread("raw:/sdcard/Documents/myfolder/test.txt") // I have an error here even if the file exists and can be read.
if f
while FileEOF(f)=0
line$ = line$+readline(f)
endwhile
CloseFile(f)
else
Message("unable to read the file 'test.txt' in : "+"/sdcard/Documents/myfolder/")
endif
do
for i=0 to listfile.length
print(listfile[i])
next
Print( ScreenFPS() )
Sync()
loop
function ProcessFiles(folder as string)
// by binkok
f as integer
i as integer
name as string
//~ PrintLine(folder)
//~ PrintRefresh()
folder = SimplifyPath(folder)+"/"
f = OpenRawFolder("raw:"+folder)
for i=0 to GetRawFolderNumFiles(f) - 1
name = folder+GetRawFolderFileName(f, i)
listfile.length = i
listfile[i] = name
//~ ProcessFiles(name)
next
for i=0 to GetRawFolderNumFolders(f) - 1
name = folder+GetRawFolderFolderName(f, i)
ProcessFiles(name)
next
CloseRawFolder(f)
endfunction
thanks
AGK2 tier1 - http://www.dracaena-studio.com