Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

External Storage
Started by Scott Harrison Jan 27 2017 10:49 AM

99 replies to this topic
[TOPIC CONTROLS]
Page 2 of 4 1 2 3 4
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

I am looking into this

 

here is RSS feed of the update logs

 

https://bitbucket.org/coronalabs/store-hosted-externalstorage/rss?token=829a4286184c5ab3c5c1b99a52d25ab9



[TOPIC: post.html]
#27

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

This should be fixed, please note you must add true at the end of functions

 

example

print( json.encode( externalStorage.listFiles(externalStorage.sdCardPath(),true)))

please visit https://scotth.tech/plugin-externalStorage to see changes



[TOPIC: post.html]
#28

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

Thanks so much Scott for the quick fixes!

One last thought, I assume there"s no easy way to get a list of files *recursively* on the plugin side, right? Basically I need to be able to get a list of all files a user might have in folders or subfolders (with paths) . I could then with lua see which of those found filenames end with .wav and allow users to select it. Kind of like how the Android app "Installer - Installer APK" scans your entire phone (folders and subfolders) looking for any .apk files.

Thank you again for the great plugin!

[TOPIC: post.html]
#29

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Thanks so much Scott for the quick fixes!

One last thought, I assume there"s no easy way to get a list of files *recursively* on the plugin side, right? Basically I need to be able to get a list of all files a user might have in folders or subfolders (with paths) . I could then with lua see which of those found filenames end with .wav and allow users to select it. Kind of like how the Android app "Installer - Installer APK" scans your entire phone (folders and subfolders) looking for any .apk files.

Thank you again for the great plugin!

Glad you like, to answers your other question. There is no magic( by that I mean easy) way to do this. You are probably better off trying to spin your own solution. This plugin gives you basically give you raw power to the phones file system. As fun as making a demo sounds, I cannot do everything( even how much I try ). I got another bug to deal with. Thanks,

Scott



[TOPIC: post.html]
#30

John_M

[GLOBAL: userInfoPane.html]
John_M
  • Enthusiast

  • 97 posts
  • Corona SDK

ok thanks, I'll give it a shot..



[TOPIC: post.html]
#31

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Hi Scott,

 

Thanks for this plugging too.

 

I have purchased it some time ago, and, I have a little question:

 

Is there any way that I can create a folder on the external storage?

 

The idea is that, my app, needs this plugging to perform some data backup, and don't want to keep the files hanging about along the external storage root. I'd love to create my own folder with my app's name, and then, save the backup files into that folder.

 

Is there any way to do it?

 

Thanks again in advance,

 

 

P.D. I have adjust my SD card as extension for the internal memory, so, the function:

 

externalStorage.isSdCardConnected()

 

gives me false, is correct isn't it?

 

Thanks again



[TOPIC: post.html]
#32

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Hi Scott,

 

Thanks for this plugging too.

 

I have purchased it some time ago, and, I have a little question:

 

Is there any way that I can create a folder on the external storage?

 

The idea is that, my app, needs this plugging to perform some data backup, and don't want to keep the files hanging about along the external storage root. I'd love to create my own folder with my app's name, and then, save the backup files into that folder.

 

Is there any way to do it?

 

Thanks again in advance,

 

 

P.D. I have adjust my SD card as extension for the internal memory, so, the function:

 

externalStorage.isSdCardConnected()

 

gives me false, is correct isn't it?

 

Thanks again

 

I am adding folder api, yes, I don't use android a lot so I cannot answer the sd card extension question



[TOPIC: post.html]
#33

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

added folder api

 

externalStorage.makeFolder("/Music/NewFolder")



[TOPIC: post.html]
#34

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Dear Scott,

 

Thanks for your quick answer and your quick solution,

 

But, I'm unable to do it to work ...

 

 

externalStorage.makeFolder("/Music/NewFolder")

 

give me an error: attempt to call field 'makeFolder' a nil value.

 

 

Perhaps the update you have performed is already not uploaded to the corona repository ?

 

 

By other hand,

 

Dear, we can create folders using the LFS as follow:

 

 

 

local temp_path = externalStorage.sdCardPath()

 
if temp_path and type (temp_path) == 'string' then
 
  -- Change current working directory
  local success = lfs.chdir( temp_path )  --returns true on success
  local new_folder_path
 
  if ( success ) then
  lfs.mkdir( "NewFolder" )
     new_folder_path = lfs.currentdir() .. "/NewFolder"
  print ("LFS SUCCESS")
  end
 
end
 
 
 print ("Folder Created")
end
 
 
 
 
But for this, we need any chance to get the root to the sdCardPath.
 
externalStorage.sdCardPath() don't return an string containing the real path, but, a function.
 
Is there any way to get the correct string to the SDPath to use LFS to manipulate the files?
 
 
I know the most difficult in your plugging is to correctly obtain the path to the sdCard, due, different Android version, comes with different paths for the external SD (sdcard, sdcard1, mnt/sdCard.... ) and I really loves the way you have performed to solve it, and for that I bought your plugging. But do you think it is possible your plugging gives us the correct path for the sd as mentioned in string format to use it with LFS ?
 
 
If not, can you arrange a correct sample, to simple do the follow?
 
 
create a Folder named 'myFolder' at the root of the SDCard.
 
copy a file from system.documentsDirectory to  that folder.
 
list the total files inside that folder (list files at SDCard/myFolder... to check if my file is there. Also can get the timestamp for that file.
 
delete certain file from that folder at SDCard.
 
copy a file from that folder (SDCard/myFolder) to the system.documentsDirectory.
 
 
As you can see, all these can be solved if you plugging simple gives or return the correct path to the SDCard in string, due, we can use LFS to manipulate all these requests.
 
Thanks again for your great job.


[TOPIC: post.html]
#35

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

My plugin is not designed to work with the lfs. I build my own solution for handling external storage. externalStorage.makeFolder("/Music/NewFolder") works I just tested it. It was not added to the lua stubs on mac or windows so I just fixed that. It should work if you ignore the error and test on device, but it should not show an error in simulator within the hour. If you want to access the sd card you should use the build in functions. This plugin allows you to transfer files from your app sandbox to android file system and vise versa.

print( json.encode( externalStorage.listFiles(externalStorage.sdCardPath(),true)))
local pathCorona = system.pathForFile( "test.txt" )
print(externalStorage.copyFile(pathCorona, externalStorage.sdCardPath().."hello123.txt", true))
print( externalStorage.deleteFile(externalStorage.sdCardPath().."test.txt") )

please read documentation



[TOPIC: post.html]
#36

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Hi again Scott,

 

Thanks for your answer.

 

 

Dear, now it works, but, please, note the follow:

 

 

1. print( externalStorage.sdCardPath() )  --> "/storage/sdcard1/" --> PERFECT!!

 

2. externalStorage.makeFolder("/NewFolder")  --> creates the folder at the internal memory root --> PERFECT!!

 

But,

3. externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder")  --> creates the folder at internal memory/storage/sdcard1 not at the external SD --> FAIL!!

 

I think, by default, externalStorage.makeFolder() assume the root of the internal memory and then concatenate the value you pass.

 

Really, the folder is created at:

 

/storage/emulated/0/storage/sdcard1/NewFolder

 

But ought to be at:

 

/storage/sdcard1/NewFolder

 

So, by any reason, the makeFolder function always concatenate the argument (the name of the folder) to the internal root path.

 

I can see the externalStorage.directory() return the internal root path (/storage/emulated/0 in my case)

 

can you revise this, and avoid to always concatenate the internal path to all the arguments passed to the makeFolder() ?

 

If you avoid to concatenate it, we can use the follow:

 

externalStorage.makeFolder( externalStorage.directory() .. "NewFolder" --> to create at internal storage

 

externalStorage.makeFolder( externalStorage.sdCardPath() .. "NewFolder" --> to create at the SD Card Root

 

 

Or arrange another way to create folders at external storage.

 

Thanks again for your great job,



[TOPIC: post.html]
#37

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Hi again Scott,

Thanks for your answer.


Dear, now it works, but, please, note the follow:


1. print( externalStorage.sdCardPath() ) --> "/storage/sdcard1/" --> PERFECT!!

2. externalStorage.makeFolder("/NewFolder") --> creates the folder at the internal memory root --> PERFECT!!

But,
3. externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder") --> creates the folder at internal memory/storage/sdcard1 not at the external SD --> FAIL!!

I think, by default, externalStorage.makeFolder() assume the root of the internal memory and then concatenate the value you pass.

Really, the folder is created at:

/storage/emulated/0/storage/sdcard1/NewFolder

But ought to be at:

/storage/sdcard1/NewFolder

So, by any reason, the makeFolder function always concatenate the argument (the name of the folder) to the internal root path.

I can see the externalStorage.directory() return the internal root path (/storage/emulated/0 in my case)

can you revise this, and avoid to always concatenate the internal path to all the arguments passed to the makeFolder() ?

If you avoid to concatenate it, we can use the follow:

externalStorage.makeFolder( externalStorage.directory() .. "NewFolder" --> to create at internal storage

externalStorage.makeFolder( externalStorage.sdCardPath() .. "NewFolder" --> to create at the SD Card Root


Or arrange another way to create folders at external storage.

Thanks again for your great job,


Try externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", true)

[TOPIC: post.html]
#38

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Hi Scott,

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", true)  --> appear to don't do anything

 

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", false)  --> create a folder at internal memory, named storage, and inside it, other named sdcard1, and inside this last, the NewFolder, so it is the very same

 

 

 

I think the true field is something similar to 'not concatenate the root for the internal memory' isn't it? but, appear to not work properly.

 

Thanks again dear,



[TOPIC: post.html]
#39

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

sorry try externalStorage.makeFolder(externalStorage.sdCardPath() .. "NewFolder", true)



[TOPIC: post.html]
#40

CesarHernandez

[GLOBAL: userInfoPane.html]
CesarHernandez
  • Enthusiast

  • 80 posts
  • Corona SDK

Dear Scott,

sorry for delay in answer. I have limited time and today have tested your suggestions.

 

Dear,

 

The following DONT WORK AT ALL AND DON'T DO ANYTHING

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "NewFolder", true) --Do nothing

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", true)  --Do nothing

externalStorage.makeFolder (externalStorage.sdCardPath() .. "NewFolder2/") --Do nothing

 

Neither of the above do anything. Don't work at all.

 

 

The following WORKS but not in a correct way, as explained for each one:

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", false) --> create a folder in internal memory, at a folder named storage/sdcard1/NewFolder

 

 

Could you revise it and let me know if there is any way to create and copy files to the external SD card ?

 

I continue thinking your routine makeFolder use the internal memory root path adding it to all the passes arguments. Any chance to not add this internal root path to the folder? I think you prepared the true second argument to do this, but, as mentioned, don't works dear.

 

I'm testing in a Android 5.0.2 with an external SDCard attached.

 

 

externalStorage.sdCardPath() --> gives me the following :      /storage/sdcard1/

 

externalStorage.isSdCardConnected() --> give me : TRUE

 

 

Could you revise this ? I need to create a folder to the external SD Card, and copy files there. It is to backup info. Internal memory is not the correct place to store the backup. Need to write to the external SD Card (externalStorage.sdCardPath)

 

Thanks again,



[TOPIC: post.html]
#41

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Dear Scott,

sorry for delay in answer. I have limited time and today have tested your suggestions.

 

Dear,

 

The following DONT WORK AT ALL AND DON'T DO ANYTHING

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "NewFolder", true) --Do nothing

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", true)  --Do nothing

externalStorage.makeFolder (externalStorage.sdCardPath() .. "NewFolder2/") --Do nothing

 

Neither of the above do anything. Don't work at all.

 

 

The following WORKS but not in a correct way, as explained for each one:

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", false) --> create a folder in internal memory, at a folder named storage/sdcard1/NewFolder

 

 

Could you revise it and let me know if there is any way to create and copy files to the external SD card ?

 

I continue thinking your routine makeFolder use the internal memory root path adding it to all the passes arguments. Any chance to not add this internal root path to the folder? I think you prepared the true second argument to do this, but, as mentioned, don't works dear.

 

I'm testing in a Android 5.0.2 with an external SDCard attached.

 

 

externalStorage.sdCardPath() --> gives me the following :      /storage/sdcard1/

 

externalStorage.isSdCardConnected() --> give me : TRUE

 

 

Could you revise this ? I need to create a folder to the external SD Card, and copy files there. It is to backup info. Internal memory is not the correct place to store the backup. Need to write to the external SD Card (externalStorage.sdCardPath)

 

Thanks again,

I am looking into it, Android considers the internal memory the External Storage. When true is added it writes raw with java file system. 



[TOPIC: post.html]
#42

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,110 posts
  • Corona SDK

@scott ever regret doing plugins?



[TOPIC: post.html]
#43

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

@scott ever regret doing plugins?


I enjoy helping developers, I wish I could make a few more dollars but still happy to do it.

[TOPIC: post.html]
#44

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,110 posts
  • Corona SDK

if you want to make $ then plugins is not the way forward... a successful game definitely is



[TOPIC: post.html]
#45

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

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. :)

[TOPIC: post.html]
#46

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 2,110 posts
  • Corona SDK

You should share your games (if you want PM me)



[TOPIC: post.html]
#47

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

Dear Scott,

sorry for delay in answer. I have limited time and today have tested your suggestions.

 

Dear,

 

The following DONT WORK AT ALL AND DON'T DO ANYTHING

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "NewFolder", true) --Do nothing

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", true)  --Do nothing

externalStorage.makeFolder (externalStorage.sdCardPath() .. "NewFolder2/") --Do nothing

 

Neither of the above do anything. Don't work at all.

 

 

The following WORKS but not in a correct way, as explained for each one:

 

externalStorage.makeFolder(externalStorage.sdCardPath() .. "/NewFolder", false) --> create a folder in internal memory, at a folder named storage/sdcard1/NewFolder

 

 

Could you revise it and let me know if there is any way to create and copy files to the external SD card ?

 

I continue thinking your routine makeFolder use the internal memory root path adding it to all the passes arguments. Any chance to not add this internal root path to the folder? I think you prepared the true second argument to do this, but, as mentioned, don't works dear.

 

I'm testing in a Android 5.0.2 with an external SDCard attached.

 

 

externalStorage.sdCardPath() --> gives me the following :      /storage/sdcard1/

 

externalStorage.isSdCardConnected() --> give me : TRUE

 

 

Could you revise this ? I need to create a folder to the external SD Card, and copy files there. It is to backup info. Internal memory is not the correct place to store the backup. Need to write to the external SD Card (externalStorage.sdCardPath)

 

Thanks again,

 

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.  



[TOPIC: post.html]
#48

andrea_corte

[GLOBAL: userInfoPane.html]
andrea_corte
  • Enthusiast

  • 36 posts
  • Corona SDK

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?


[TOPIC: post.html]
#49

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,803 posts
  • Enterprise

 

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)


  • andrea_corte likes this

[TOPIC: post.html]
#50

andrea_corte

[GLOBAL: userInfoPane.html]
andrea_corte
  • Enthusiast

  • 36 posts
  • Corona SDK

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



[topic_controls]
Page 2 of 4 1 2 3 4
 
[/topic_controls]