package com.demo.sqlite;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Demo_sqliteActivity extends Activity{
TextView text;
SQLiteDatabase db;
DatabaseDump dump;
Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
text.append(msg.obj.toString()+"\n");
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView) findViewById(R.id.text);
// db=SQLiteDatabase.openOrCreateDatabase("/sdcard/MosRawFile/databases/mosSql.db", null);
// dump=new DatabaseDump(db, "/sdcard/mos.xml");
// Log.d("TAG", db.getPath());
// SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
// Log.d("TAG", "开始时间:"+sdf.format(new Date(System.currentTimeMillis())));
// long l=System.currentTimeMillis();
//dump.exportData();
// long n=System.currentTimeMillis();
// Log.d("TAG", "时间长短:"+(n-l)+"");
// Log.d("TAG", "结束时间:"+sdf.format(new Date(System.currentTimeMillis())));
Button btn_ls = (Button) findViewById(R.id.btn_ls);
btn_ls.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// String str[]=new String[]{"su -s","sqlite3 /mosSql.db","select * from DLCall;"};
// // String str[]=new String[]{"ls",""};
// // do_exec(str);
// // do_exec("select * from DLCall;");
//
//
// Process p;
// try {
// p = Runtime.getRuntime().exec(str);
// StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR",handler);
//
// // kick off stderr
// errorGobbler.start();
//
// StreamGobbler outGobbler = new StreamGobbler(p.getInputStream(), "STDOUT",handler);
// // kick off stdout
// outGobbler.start();
//
// p.waitFor();
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
do_exec("/x.sh");
}
});
Button btn_cat = (Button) findViewById(R.id.btn_cat);
btn_cat.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
do_exec("cat /proc/version");
}
});
Button btn_rm = (Button) findViewById(R.id.btn_rm);
btn_rm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
do_exec(new String []{"ls","pwd"});
}
});
Button btn_sh = (Button) findViewById(R.id.btn_sh);
btn_sh.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
do_exec("/system/bin/sh /mnt/sdcard/test.sh 123");
}
});
}
String do_exec(String cmd) {
String s = "\n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
p.waitFor();
while ((line = in.readLine()) != null) {
s += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
text.setText(s);
return cmd;
}
String do_exec(String[] cmd) {
String s = "*****\n";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
s += line + "\n";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
text.setText(s);
return "";
}
}
评论4
最新资源