Jump to content

Execute system command from Kotlin code?

Go to solution Solved by wasab,

Kotlin can run on Java virtual machine so it can run all the standard Java libraries so just use the Java runtime. 

Spoiler

Runtime.getRuntime().exec("...")

If you are programming on Android, "su" is an useful command if your phone is rooted. Your app can do crazy thing with the system.... Just some tips ?

Kotlin can run on Java virtual machine so it can run all the standard Java libraries so just use the Java runtime. 

Spoiler

Runtime.getRuntime().exec("...")

If you are programming on Android, "su" is an useful command if your phone is rooted. Your app can do crazy thing with the system.... Just some tips ?

Sudo make me a sandwich 

Link to post
Share on other sites

29 minutes ago, wasab said:

Kotlin can run on Java virtual machine so it can run all the standard Java libraries so just use the Java runtime. 

  Reveal hidden contents

Runtime.getRuntime().exec("...")

If you are programming on Android, "su" is an useful command if your phone is rooted. Your app can do crazy thing with the system.... Just some tips ?

Thanks! :)

Link to post
Share on other sites

38 minutes ago, wasab said:

If you are programming on Android, "su" is an useful command if your phone is rooted. Your app can do crazy thing with the system.... Just some tips ?

I am interested in Android Programming! Please tell me more about it and how can I use it? How can I use "su" in my Android app? Please give some examples. 

Thanks

Link to post
Share on other sites

19 minutes ago, LiquidFox said:

I am interested in Android Programming! Please tell me more about it and how can I use it? How can I use "su" in my Android app? Please give some examples. 

Thanks

Well, I can't and won't teach you. I don't have that much free time in my life but you can learn Android programming  from watching YouTube. 

 

And Unix shell command also from youtube. Android runs on Linux kernel so unix bash commands can be run on it as well. Don't expect all the command line ulities of Linux to be on there though. Use adb to run shell commands or download a terminal emulator from the playstore. 

 

 

And read Google developer documentation for more information on Android development. 

https://developer.android.com

 

 

Sudo make me a sandwich 

Link to post
Share on other sites

3 minutes ago, wasab said:

Well, I can't and won't teach you. I don't have that much free time in my life but you can learn Android programming  from watching YouTube. 

 

And Unix shell command also from youtube. Android runs on Linux kernel so unix bash commands can be run on it as well. Don't expect all the command line ulities of Linux to be on there though. Use adb to run shell commands or download a terminal emulator from the playstore. 

 

 

And read Google developer documentation for more information on Android development. 

https://developer.android.com

 

 

Thanks!

Link to post
Share on other sites

1 hour ago, wasab said:

If you are programming on Android, "su" is an useful command if your phone is rooted.

I just wanna know how to use "su", 

Like this?: 

Runtime.getRuntime().exec("su mkdir Games")

Runtime.getRuntime().exec("su rm -rf Games")

Link to post
Share on other sites

Just now, LiquidFox said:

I just wanna know how to use "su", 

Like this?: 

Runtime.getRuntime().exec("su mkdir Games")

Runtime.getRuntime().exec("su rm -rf Games")

 Runtime.getRuntime().exec("su")

https://en.m.wikipedia.org/wiki/Su_(Unix)

 

 

Sudo make me a sandwich 

Link to post
Share on other sites

14 minutes ago, wasab said:

Well, I can't and won't teach you. I don't have that much free time in my life but you can learn Android programming  from watching YouTube. 

 

And Unix shell command also from youtube. Android runs on Linux kernel so unix bash commands can be run on it as well. Don't expect all the command line ulities of Linux to be on there though. Use adb to run shell commands or download a terminal emulator from the playstore. 

 

 

And read Google developer documentation for more information on Android development. 

https://developer.android.com

 

 

BTW I am learning Java, Python and Kotlin on Mimo: Learn to Code app, SoloLearn, Programming Hub and Udemy. 

Link to post
Share on other sites

6 minutes ago, LiquidFox said:

Is this work like "sudo su" on Linux?? 

Sudo is not preinstalled on Android. Actually, su isn't  preinstalled on most commercial Android phones either. If you device isn't rooted and you run this command in your terminal emulator, it will tell you no su binary found. 

Sudo make me a sandwich 

Link to post
Share on other sites

21 minutes ago, wasab said:

Sudo is not preinstalled on Android. Actually, su isn't  preinstalled on most commercial Android phones either. If you device isn't rooted and you run this command in your terminal emulator, it will tell you no su binary found. 

What will happen if I run it on a rooted phone? 

Does the superuser manager like SuperSu or Magisk prompt appear saying that this app is requesting superuser permission? 

Link to post
Share on other sites

20 hours ago, wasab said:

Kotlin can run on Java virtual machine so it can run all the standard Java libraries so just use the Java runtime. 

  Reveal hidden contents

Runtime.getRuntime().exec("...")

If you are programming on Android, "su" is an useful command if your phone is rooted. Your app can do crazy thing with the system.... Just some tips ?

How to convert these python programs shown in the video tutorials down below to Java or Kotlin programs??

TL;DR 

Python's Socket module alternative for Java or Kotlin.

Part One: 



Part Two: 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×