Android Shell Code

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
thecoolpeople
Prole
Posts: 1
Joined: Sat Mar 14, 2020 4:00 pm

Android Shell Code

Post by thecoolpeople » Sat Mar 14, 2020 4:12 pm

Hello Programmers:

I have some cool code pieces, which can help many of you! All of these are for android, so have fun. Of course, there are many more, but I think, these are the important ones. If you have some more questions, please write them below! :awesome:
When you have some improvements, write me a private message, or below.

I will improve and find more of such cool commands, and I will share them with you!

Open file with the standard program: (by thecoolpeople)

Code: Select all

local openFile = function(path, mimetype)
  path = love.filesystem.getSaveDirectory() .. "/" .. path
  path = "file://" .. path
  os.execute("am start --user 0 -a android.intent.action.VIEW -d " .. path .. " -t " .. mimetype)
end
Share file: (by thecoolpeople)

Code: Select all

local shareFile = function(path, mimetype)
  path = love.filesystem.getSaveDirectory() .. "/" .. path
  path = "file://" .. path
  os.execute("am start --user 0 -a android.intent.action.SEND -t " .. mimetype .. " --eu android.intent.extra.STREAM " .. path)
end

Kunologist
Prole
Posts: 2
Joined: Fri Mar 20, 2020 9:21 am

Re: Android Shell Code

Post by Kunologist » Thu Mar 26, 2020 12:58 am

Woah, so happy to see that os.execute() is working on LOVE Android!
So I guess os.time() and os.date() would work too!

User avatar
AuahDark
Prole
Posts: 38
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Re: Android Shell Code

Post by AuahDark » Thu Mar 26, 2020 2:40 am

Beware that code won't work in Android Nougat and later due to file:// URI banned in that and later version of Android. Of course all os.* functions work as they should, only limited by system permissions.
Profile. I don't always online in forum, so Discord is preferred.

Kunologist
Prole
Posts: 2
Joined: Fri Mar 20, 2020 9:21 am

Re: Android Shell Code

Post by Kunologist » Thu Mar 26, 2020 4:33 pm

And I found a tiny bit more interesting below os.execute(). With this function we can make pur LOVE game write contents to external directories without root permission. The idea is the Linux behind every Android device.

If you want to create an external directory, use:

Code: Select all

os.execute("mkdir /sdcard/lovegame/savedata/")
(The path is just an instance of using mkdir. Avoid using /sdcard, it's a bad practice after all.)

And to write a file (if doesn't exist, will create it), use:

Code: Select all

os.execute([[echo 'Hello World!' >/sdcard/lovegame/savedata/helloworld.txt]])
And that's pretty amazing given that 11.3 or Android still left us with a backdoor to write external files.

Bad thing I haven't found out how to read, so bleh. Any ideas?

User avatar
Guard13007
Party member
Posts: 128
Joined: Sat Oct 25, 2014 3:42 am
Location: Internet, USA
Contact:

Re: Android Shell Code

Post by Guard13007 » Fri May 15, 2020 8:42 am

Can you please explain why writing to /sdcard is considered bad practise and what we should use instead? Just stating not to do it without an alternative isn't very helpful. :(

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests