execute adb shell command at runtime from android application

3,421 views
Skip to first unread message

joy joy

unread,
Apr 12, 2010, 7:58:03 AM4/12/10
to android-...@googlegroups.com

hi.

In my application I want to create a directory xyz in sdcard at the runtime from the my Application.

But it doesn't work.

Here is my code..

public class process extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

       
String[] str ={"mkdir","/sdcard/xyz"};

             
try {

       
Process ps = Runtime.getRuntime().exec(str);
       
try {
   ps
.waitFor();
 
} catch (InterruptedException e) {
   
// TODO Auto-generated catch block
   e
.printStackTrace();
 
}
       
}

       
catch (IOException e) {
       
Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
       
}

}

}

a genius

unread,
Apr 12, 2010, 8:19:10 AM4/12/10
to android-platform
This has nothing at all to do with adb.
adb is the client/server protocol used for debugging android remotely
via network or USB.

What you are trying to do seems incredibly pointless.... you shouldn't
be running a shell command to create a directory.

Read this: http://groups.google.com/group/android-developers/browse_thread/thread/64fb55b5bd03a2cd

Addy

unread,
Apr 12, 2010, 9:07:24 AM4/12/10
to android-platform

On Apr 12, 5:19 pm, a genius <droidhac...@gmail.com> wrote:
> This has nothing at all to do with adb.
> adb is the client/server protocol used for debugging android remotely
> via network or USB.
>
> What you are trying to do seems incredibly pointless.... you shouldn't
> be running a shell command to create a directory.
>

> Read this:http://groups.google.com/group/android-developers/browse_thread/threa...


>
> On Apr 12, 7:58 am, joy joy <joyy.bl...@gmail.com> wrote:
>
> > hi.
>
> > In my application I want to create a directory xyz in sdcard at the runtime
> > from the my Application.
>
> > But it doesn't work.
>
> > Here is my code..
>
> > public class process extends Activity {
>
> > /** Called when the activity is first created. */
>
> > @Override
>
> > public void onCreate(Bundle savedInstanceState) {
>
> > super.onCreate(savedInstanceState);
>
> >     setContentView(R.layout.main);
>
> >        String[] str ={"mkdir","/sdcard/xyz"};
>
> >               try {
>
> >         Process ps = Runtime.getRuntime().exec(str);
> >         try {
> >    ps.waitFor();
> >   } catch (InterruptedException e) {
> >    // TODO Auto-generated catch block
> >    e.printStackTrace();
> >   }
> >         }
>
> >        catch (IOException e) {
> >         Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
> >        }
>
> > }
> > }
>
>

ok thnx.

nw can I run executable file within process command at the runtime of
application.

from the above code my command string is now..


String[] str = "./extract_xxxfile /sdcard/abc.xxx /sdcard/
extracted_file/";

Here extract_xxxfile is the arm executable file and its in system/lib.

I want to extract /sdcard/abc.xxx file in /sdcard/extracted_file
directory.


It gives runtime directory null and environment null exception (IO
Exception).

can you help me?

Marek Pola

unread,
Apr 12, 2010, 9:31:09 AM4/12/10
to android-platform
Reply all
Reply to author
Forward
0 new messages