I am looking into it, Android considers the internal memory the External Storage. When true is added it writes raw with java file system.
I enjoy helping developers, I wish I could make a few more dollars but still happy to do it.
if you want to make $ then plugins is not the way forward… a successful game definitely is
I agree, I don’t think I am going to be a millionaire of plugins. I do game development as well. I just don’t talk much about it.
You should share your games (if you want PM me)
I think I found the answer to via stack overflow
http://stackoverflow.com/a/40201333
To be clear right now this plugin does pretty much everything. You use the raw File api on Java to write and read anywhere you want unfortunately there are certain places the app cannot read or write with out rooting the android phone. To be clear I am not an android expert, I use an iPhone 7 as my main phone and I am not to familiar with the limitation of android. I have been trying to write files to sd card for a while with java but android does not like it. I am still looking into writing in app folder on sd card but it may not be the solution you are looking for. I wish there was something I could due but I am limited the walls of phone os. I did all my testing on a KitKat device. I will try to find a solution on my 5.1 device but I am not hopeful. If anyone has any solution feel free to share.
To reiterate when I made this plugin I was making it to access all data inside Environment.getExternalStorageDirectory() but android considers this to be the phones internal memory which is odd to me.
Good evening
I’m using the external storage plugin.
my project is to take a .txt file from the download folder on your phone and use the app. This is my code:
local text = display.newText( “Hello World!”, 150, 100, native.systemFont, 16 )
text:setFillColor( 1, 0, 0 )
printFiles = widget.newButton( {
label = “Print Files”,
id = “printFiles”,
onEvent = function ( e )
if (e.phase == “began”) then
printFiles.alpha = .3
else
printFiles.alpha = 1
print( “Files” )
print( “----------------” )
externalStorage.getFile("/test.txt", pathDocs)
local file = io.open( pathDocs, “r” )
if file then
local contents = file:read( “*a” )
print( “file says:”…contents )
text.text = contents
io.close( file )
else
print(“no file saved”)
end
print( “----------------” )
end
end
} )
if the .txt file in the archive of the phone works, if the file is not in the download folder.
Someone can help me?
if you want a file in the downloads folder you would do
externalStorage.getFile("/Download/test.txt", pathDocs)
Perfect, that’s just what I needed
Thanks so much
Best regards
Dear Scott,
Great job dear. I know it is not as easy as appear.
That’s ought to be the reason. I have been reading about android limitation to certain folders.
Really, for me will be enough to write to the app’s folder at the sd. I mean, you mentioned the following: “I am still looking into writing in app folder on sd card but it may not be the solution you are looking for”…
This solution can be fine dear. I only need to write to a folder where the user later can take the files and the app can read the files. The idea is that SD can works as a backup, so, if the user change the phone, he has the backup file in the app folder at the sd card.
I have tried with the proper name of the app to create the folder but I can’t do it.
Have you tested creating a folder for the app (package name) at sd and works? Can you share the code to do it through your plugging?
For example, the app with package name com.example.foo can now freely access Android/data/com.example.foo/ on external storage devices with no permissions
Any chance to obtain the route to create the app data folder ? in the above example "Android/data/com.example.foo/ ?
Will works Context.getExternalFilesDirs()
Can pass this variable through your plugging ?
I know it is terrible different from one android version to other, according to the docs you sent dear.
Any chance will be very very appreciate dear.
All in all thanks so much for your excellent plugging. Great job dear.
Your,
Dear Scott, perfect. Tganks so much.
Dear, im’turning crazy to get a file passed to Android (intent). I have configured the intents to autolanch my app with certain file extension, and i have the path. But appear to be an stream. Can i use your plug ( External storage) to get this fike? I’ve seen a tutorial to do it for ios, but not for Android. Can you help me or guide a little?
Thanks so much again
This plugin was not specifically designed for that purpose. If it works, that’s great please feel free to share.
Dear Scott,
I would like list the files of “myFolder”
print( json.encode( externalStorage.listFiles("/myFolder",true)))
I get “java.lang.NullPointerException” is my syntax good?
/myFolder
file1.txt
file2.txt
… fileN.txt
but when i use print(externalStorage.doesFileExist("/myFolder/file1.txt")) i get true… I am confused
when i use print( json.encode( externalStorage.listFiles()))
I get no error and the list of all folders and files.
thanks
try
print( json.encode( externalStorage.listFiles("/myFolder")))
the true looks at the root of the phone. Ie phone os and sd card
If you want to look at the phone’s storage where all the phone personal files are kept remove the true.
you may also want to use this api
externalStorage.doesFileExist("/myFolder")
Hello, Scott.
I just acquired the plugin and I’m doing the tests on my mobile, with Android 8.0.
After configuring build.settings like this:
settings =
{
plugins = { [“plugin.externalStorage”] = { publisherId = “tech.scotth”, supportedPlatforms = { android = true, }, }, __},
android =
{
usesPermissions =
{ “android.permission.WRITE_EXTERNAL_STORAGE”,
“android.permission.READ_EXTERNAL_STORAGE”,
},
}
according to the documentation, I’m encountering some problems.
First of all, when I try this:
externalStorage.isSdCardConnected ()
I get a false result (but I have a micro SD card).
On the other hand, when I try this sentence (which also appears in this post):
print (json.encode (externalStorage.listFiles (externalStorage.sdCardPath (), true)))
I get the error: bad argument # 1 to ‘listfiles’ (expected string, got boolean)
The same thing happens to me with other externalStorage routines …
Please, I will appreciate your help.
Thank you very much.
J. M. Flores
Have you already requested real-time permission
native.showPopup( "requestAppPermission", { appPermission = "Storage", urgency = "Critical", listener= function ( e ) end} )
Hi, Scott.
I have forced the permission in real time just as you indicated.
During the execution, the App asked for my permission, and I granted it (is it necessary to force the permission like this for the normal execution?).
But, after this, if I execute the sentence:
native.showAlert ( “LIST”, json.encode (externalStorage.listFiles (externalStorage.sdCardPath(), true)) )
Give an execution error indicating: LuaRuntimeException: bad argument # 1 to ‘listFiles’ (expected string, got function)
And in the case of externalStorage.isSdCardConnected(), it continues returning _ false _.
I look forward to your instructions.
Thank you very much