Friday, October 29, 2010

Running Android Native Code in your Android app





Just came over a post asking for Android's Logging Best Practices that took me to android log collector. Delving more deeper into log collector's code I got the below code to executes the specified command and its arguments in a separate native process.

All you need is just below code
String myStringArray[]= {"logcat","-d"};
Process process = Runtime.getRuntime().exec(myStringArray);
Setup the permissions for the required operation & you r done!Enjoy

But keep in mind Use Native Methods Judiciously & do check jon oberheide's Android Hax
And thanks to android-log-colllector team for the code.


Though the post describes a way of dropping a shell command from an app , check this for more ways to run shell commands from your app.
And also this  & I have heard MarketEnabler source offers a nice ShellInterface class.
So go get your app runnning!
See ya there at ./a.in

Friday, October 22, 2010