public class adbActivity extends Activity {
private final static String[] ARGS1 = {"adb","connect","10.10.10.103"};
private final static String[] ARGS2 = {"adb","install","/storage/sdcard0/PreLancherActivity.apk"};
private final static String[] ARGS3 = {"adb","shell"};
private final static String TAG = "com.yin.system";
Button mButton;
TextView myTextView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button) findViewById(R.id.bu1);
myTextView = (TextView) findViewById(R.id.txt1);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
getResult1();
myTextView.setText(getResult2());
}
});
}
public String getResult1(){
ShellExecute cmdexe = new ShellExecute ( );
String result="";
try {
result = cmdexe.execute(ARGS1, null);
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
return result;
}
public String getResult2(){
ShellExecute cmdexe = new ShellExecute ( );
String result="";
try {
result = cmdexe.execute(ARGS2, null);
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
return result;
}
private class ShellExecute {
/*
* args[0] : shell 命令 如"ls" 或"ls -1";
* args[1] : 命令执行路径 如"/" ;
*/
public String execute ( String [] cmmand,String directory)
throws IOException {
String result = "" ;
try {
ProcessBuilder builder = new ProcessBuilder(cmmand);
if ( directory != null )
builder.directory ( new File ( directory ) ) ;
builder.redirectErrorStream (true) ;
Process process = builder.start ( ) ;
//得到命令执行后的结果
InputStream is = process.getInputStream ( ) ;
byte[] buffer = new byte[1024] ;
while ( is.read(buffer) != -1 ) {
result = result + new String (buffer) ;
}
is.close ( ) ;
} catch ( Exception e ) {
e.printStackTrace ( ) ;
}
return result ;
}
}
}
private final static String[] ARGS1 = {"adb","connect","10.10.10.103"};
private final static String[] ARGS2 = {"adb","install","/storage/sdcard0/PreLancherActivity.apk"};
private final static String[] ARGS3 = {"adb","shell"};
private final static String TAG = "com.yin.system";
Button mButton;
TextView myTextView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button) findViewById(R.id.bu1);
myTextView = (TextView) findViewById(R.id.txt1);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
getResult1();
myTextView.setText(getResult2());
}
});
}
public String getResult1(){
ShellExecute cmdexe = new ShellExecute ( );
String result="";
try {
result = cmdexe.execute(ARGS1, null);
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
return result;
}
public String getResult2(){
ShellExecute cmdexe = new ShellExecute ( );
String result="";
try {
result = cmdexe.execute(ARGS2, null);
} catch (IOException e) {
Log.e(TAG, "IOException");
e.printStackTrace();
}
return result;
}
private class ShellExecute {
/*
* args[0] : shell 命令 如"ls" 或"ls -1";
* args[1] : 命令执行路径 如"/" ;
*/
public String execute ( String [] cmmand,String directory)
throws IOException {
String result = "" ;
try {
ProcessBuilder builder = new ProcessBuilder(cmmand);
if ( directory != null )
builder.directory ( new File ( directory ) ) ;
builder.redirectErrorStream (true) ;
Process process = builder.start ( ) ;
//得到命令执行后的结果
InputStream is = process.getInputStream ( ) ;
byte[] buffer = new byte[1024] ;
while ( is.read(buffer) != -1 ) {
result = result + new String (buffer) ;
}
is.close ( ) ;
} catch ( Exception e ) {
e.printStackTrace ( ) ;
}
return result ;
}
}
}