Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
LinkBack Thread Tools
Old April 2nd, 2013, 06:43 AM   #1 (permalink)
New Member
Thread Author (OP)
Join Date: Apr 2013
Posts: 1
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default How to execute shell commands in android app?

Hi All,

I'm new to android app's.
I need to execute following command in my app.
command: echo "1" > /sys/manager0/enable

I tried this with following code in my app.

Process p = Runtime.getRuntime().exec("su");
DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
String cmd = "echo \"1\" /sys/manager0/enable";

There is no error and app executed perfectly but there is no change in the /sys/manager0/enable

Please give suggest some solution to this.

Thanks in advance.

kbn456 is offline  
Reply With Quote
sponsored links
Old April 3rd, 2013, 01:52 AM   #2 (permalink)
Join Date: Apr 2012
Location: London
Posts: 101
Device(s): ZTE Skate, Ainol Novo7 Aurora
Carrier: Not Provided

Thanks: 2
Thanked 24 Times in 23 Posts

It looks like you are missing a ">" character in your command. The command yo are executing will just print "1 /sys/manager0/enable" to stdout.
GeorgeN is offline  
Reply With Quote
Old April 6th, 2013, 11:37 AM   #3 (permalink)
Senior Member
jonbonazza's Avatar
Join Date: Jul 2010
Gender: Male
Posts: 1,935
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts

Also, in order to successfully execute "su", you need to ensure that the device has root access.
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
shell, shell commands

Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

All times are GMT -5. The time now is 02:42 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.