edit: not much use in this thread anymore, except maybe a good reference for people making an app
How about rebooting the phone? Will that work?
well yeah, but i don't think people will pay for an app that reboots your phone each time you change the volume settings
I think its, Runtime.getRuntime.exec("your command");
have you seen this?
http://forum.xda-developers.com/showpost.php?p=3434331&postcount=35
hamshu said:
I think its, Runtime.getRuntime.exec("your command");
Click to expand...
Click to collapse
do you think you could elaborate a little more?
i'm still a complete java noob
Process process = Runtime.getRuntime().exec("killall mediaserver");
That line should do it.
hamshu said:
Process process = Runtime.getRuntime().exec("killall mediaserver");
That line should do it.
Click to expand...
Click to collapse
i've got:
try {
Process process = Runtime.getRuntime().exec("killall mediaserver");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
and it doesn't seem to do anything.
any ideas?
try {
Process process = Runtime.getRuntime().exec("sh");
DataOutputStream out = new DataOutputStream(process.getOutputStream());
out.writeBytes("killall mediaserver\n");
out.writeBytes("exit\n");
out.flush();
} catch (IOException e) {
e.printStackTrace();
}
try this, see what it does man
or try this:
Code:
try {
Class<?> execClass = Class.forName("android.os.Exec");
Method createSubprocess = execClass.getMethod("createSubprocess",
String.class, String.class, String.class, int[].class);
Method waitFor = execClass.getMethod("waitFor", int.class);
int[] pid = new int[1];
FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(
null, "/system/xbin/bb/killall", "mediaserver", null, pid);
FileInputStream in = new FileInputStream(fd);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String output = "";
try {
String line;
while ((line = reader.readLine()) != null) {
output += line + "\n";
}
} catch (IOException e) {
}
waitFor.invoke(null, pid[0]);
return output;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
} catch (SecurityException e) {
throw new RuntimeException(e.getMessage());
} catch (NoSuchMethodException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalArgumentException e) {
throw new RuntimeException(e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException(e.getMessage());
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getMessage());
}
the last bit of code i posted dude i know works with an ls command, but with this, we are trying to spawn killall and pass the mediaserver argument, so i dont know if the stack will even handle this.... doesnt hurt to try though
corp769 said:
the last bit of code i posted dude i know works with an ls command, but with this, we are trying to spawn killall and pass the mediaserver argument, so i dont know if the stack will even handle this.... doesnt hurt to try though
Click to expand...
Click to collapse
From the little I know about Android Development, I think that it will work. Then again, I am not a Java coder nor a Android Developer(C# coding ftw). Sorry about getting the Java code wrong, like I stated, I don't code any Java.
It's cool...meltus, how's it going? You have a pm btw...
sorry guys, not had any success yet, but my girlfriends come round so i'll be away for a while
I suppose you need superuser privileges to kill the mediaserver.
This might work :
Process process = Runtime.getRuntime().exec("su -c \"killall mediaserver\"");
Meltus said:
sorry guys, not had any success yet, but my girlfriends come round so i'll be away for a while
Click to expand...
Click to collapse
Pervert lol JK
Zappletoo said:
I suppose you need superuser privileges to kill the mediaserver.
This might work :
Process process = Runtime.getRuntime().exec("su -c \"killall mediaserver\"");
Click to expand...
Click to collapse
this kinda works. i get a SU permission request, but it doesn't reboot the mediaserver. any ideas? ><
alritewhadeva said:
Pervert lol JK
Click to expand...
Click to collapse
lies
goddammit i hate this damn app lol ><
now i've run across another problem, which is, i just realised the system needs to be in read/write mode (im an idiot).
so:
Code:
try {
Process process = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
works fine. makes an SU request popup thing appear, but...
Code:
try {
Process process = Runtime.getRuntime().exec("mount -o rw,remount /dev/block/mtdblock3 /system");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
afterwards doesn't do anything. anyone know why this isn't working?
damn, i hate java lol
EDIT: I've also realised that
Code:
(Process process = Runtime.getRuntime().exec("su");
works fine but replacing it with
Code:
(Process process = Runtime.getRuntime().exec("reboot");
does nothing?!? wtf's going on!! lol
ONLY su works. no other commands seem to do anything
I'm not a coder by any means (more like a beta tester, but I can go through a code and 'see' it pretty easily) and I've often refered to this specific code for sms backup for root user app to do basic things..it basically uses two buttons and sends commands to the system. Check out the source code to see if it helps any: http://code.google.com/p/sms-backup-root/
Specifically the event when a button is pressed (notice it gets 'su' the same way you currently do, but does the actual commands differently):
Code:
backup.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Process process = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
[B]os.writeBytes("cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard \n");[/B]
[B]os.writeBytes("exit\n");[/B]
os.flush();
process.waitFor();
builder.setMessage("Backup done.. Found it in /sdcard/mmssms.db");
builder.show();
} catch (Exception e) {
return;
}
finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
// Be Happy :)
}
}
return;
} });
It uses writebytes to send the code to the os. Try your code around that template and it may give you what you want.
Again im no coder, but there are a lot of open source apps that can give you a start towards what you want to do. Hope that helps!
p.s. love the audio mods, keep up the great work! Let me know if you want graphic work :]
Here you go.
Runtime rt = Runtime.getRuntime();
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("reboot");
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
I just ran this on my phone and it rebooted.... Once you start the process, you use .writeBytes to "type to it". As if you were at the terminal and just typed "su"...
Instead of "reboot", you could do "killall mediaserver" or anything else you want to type to the console...
Related
This is my code:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo(@"Windows\Camera.exe", "");
p.Start();
But a message box says it's fail to invoke camera.
I don't know why.
I saw the Camera.lnk has content as :"40#:MSCAMERA?shellres.dll,-8263"
Is that any argument?
I have the same problem, and not much time do resolve. I solve calling a shortcut of camera.
try
{
using (Process proc = new Process())
{
if (!File.Exists(@"\Windows\Camera.lnk"))
{
MessageError.ShowError("Câmera do dispositivo não detectada.", null, MessageError.Icone.Informacao, "[FOTOGRAFAR]");
return;
}
proc.StartInfo = new System.Diagnostics.ProcessStartInfo(@"\Windows\Camera.lnk", string.Empty);
proc.Start();
}
}
catch (Exception ex)
{
MessageError.ShowError(ex.Message + "\r\n\r\n" + ex.StackTrace);
}
Hi, how would u go about incoporating file commands such as delete into and android app in eclipse which i am using ?
Thanks
For manipulating files, you should look at java.io.File
i.e.
File file = new File("path");
file.delete();
Hey, thanks for that i tried it..it works for files but for deleting folders that are not empty it doesnt work ? ne way to work around that ?
Thanks Again For Your Quick Reply
I used this in my Audio Hack app and it worked nicely
Code:
Process process = null;
try {
process = Runtime.getRuntime().exec("su");
} catch (IOException e1) {
e1.printStackTrace();
}
DataOutputStream os = new DataOutputStream(process.getOutputStream());
try {
os.writeBytes("busybox rm -r blah/blah/blah \n");
} catch (IOException e) {
e.printStackTrace();
}
try {
os.writeBytes("exit\n");
} catch (IOException e) {
e.printStackTrace();
}
try {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
this just runs any busybox command as root so you can do whatever you want.
it seems to only work for me with busybox at the start though, meaning anyone using it must have busybox.
hope this answers your question
Hmmm....nice script u have there...so im tryin to make a script for my app where it would go into a directory..get the filenames....n substitute that into the filename.delete() command....can neone help ?
Also on most command prompt/shells....when u do delete folder/*.* it deletes everything in tht folder...no substitute for android ?
You need to use caution when using that approach since;
1) it requires root (at least his example does),
*2*) it is dependent on what commands are available on the particular system. You can't rely on anything here.
The workaround for deleting non-empty directories is to first delete the contents in order to MAKE them empty.
It is fairly simple to write a recursive delete function;
void recursiveDelete(String path){
File file = new File(path);
if (!file.delete() && file.isDirectory()){
String[] filelist = file.list();
for (int i=0; i<filelist.length; i++) recursiveDelete(filelist);
file.delete();
}
}
I don't know what the paths that are returned by file.list() look like... there is another function "isAbsolute()" to check if it is a relative or absolute path returned... if it is a relative path, then you want to do your recursiveDelete on path+"/"+filelist.
Note: you could also take this approach, which is probably a little more clean;
void recursiveDelete(File file){
if (!file.delete() && file.isDirectory()){
File[] filelist = file.listFiles();
for (int i=0; i<filelist.length; i++) recursiveDelete(filelist);
file.delete();
}
}
This approach solves the whole absolute/relative path question. You just have to remember to
recursiveDelete(new File("path"));
Instead of:
recursiveDelete("path");
Daneshm90 said:
Hmmm....nice script u have there...so im tryin to make a script for my app where it would go into a directory..get the filenames....n substitute that into the filename.delete() command....can neone help ?
Also on most command prompt/shells....when u do delete folder/*.* it deletes everything in tht folder...no substitute for android ?
Click to expand...
Click to collapse
Actually, what he is doing is not at all scripted... he is running a SHELL COMMAND.
Hello Forum,
I want to debug this code:
Code:
try {
sendRequest(methodName, __envelope, __httpTransport); // Exception is thrown
} finally {
if (__httpTransport.debug) { // A Breakpoint stops the execution in this line. __httpTransport.debug == false. I press F8 (Next Stmnt)
if (__httpTransport.requestDump != null) {
android.util.Log.i("requestDump", __httpTransport.requestDump);
}
if (__httpTransport.responseDump != null) {
android.util.Log.i("responseDump", __httpTransport.responseDump); // Why is this the next line?
}
}
}
I have set a breakpoint on the first stmnt in the finally block. I can see that __httpTransport.debug is false. Now I press F8 to go to the next Stmnt. Why is the next android.util.Log.i() line? In my opinion the debugger should jump to the next stmnt after the finally block? I have done a recompile and reopend Android Studio.
Thanks
Peter
I am new in android development. In the first tutorial I saw that they use code like below for button function. (They were showing to make calculator and this is not that code) and was just adding this in the attribute menu with onclick.
Code:
public void onpressButton(View v)
{
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
However, from the next tutorial while they were using Toast they always started using onClickListener for which I need to write a lot of code than before .
Code:
public void addListnerToCheckBox() {
check1 = (CheckBox)findViewById(R.id.checkBox_dog);
check1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
}
}
);
}
But the same thing can be done by the first code I have written. Then why are they using onClickListener?
tanvir108115 said:
I am new in android development. In the first tutorial I saw that they use code like below for button function. (They were showing to make calculator and this is not that code) and was just adding this in the attribute menu with onclick.
Code:
public void onpressButton(View v)
{
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
However, from the next tutorial while they were using Toast they always started using onClickListener for which I need to write a lot of code than before .
Code:
public void addListnerToCheckBox() {
check1 = (CheckBox)findViewById(R.id.checkBox_dog);
check1.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText t1=(EditText) findViewById(R.id.editText);
Toast.makeText(MainActivity.this,t1.getText(),Toast.LENGTH_SHORT).show();
}
}
}
);
}
But the same thing can be done by the first code I have written. Then why are they using onClickListener?
Click to expand...
Click to collapse
Because the setOnClickListener is a method which is listening for onClick events on a particular object in your case the Button, so when you press that button it will do the things you listed in the onClick method
But even with the first code it executes the commands written in the function.
I finding a correct way to start some app when started Android or restared
I have something like
Code:
public void startSomeApp() {
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("xxx.xxx.xxx");
if (launchIntent != null) {
context.startActivity(launchIntent);
}
}
But was wonder a correct way where should I put?
I try to push to
Code:
public void initZygote(StartupParam startupParam) throws Throwable {
startSomeApp();
}
But problem with context, any trick please?
1001z said:
I finding a correct way to start some app when started Android or restared
I have something like
But was wonder a correct way where should I put?
I try to push to
But problem with context, any trick please?
Click to expand...
Click to collapse
The correct way is without Xposed! Use the Android BOOT_COMPLETED broadcast.