获得root权限和蓝牙设置.doc
文本预览下载声明
任务要求:root权限源代码和蓝牙设置
文件管理器一般在没有root的手机,使用以下下权限即可对SD卡的文件进行操作,对手机的非系统文件夹进行操作,对root过的手机,文件管理管理器可以申请更高的权限(获得root权限),对手机的系统文件夹进行操作,比如system、data等系统文件夹。
uses-permission android:name=android.permission.READ_PHONE_STATE /
uses-permission android:name=android.permission.WRITE_OWNER_DATA /
uses-permission android:name=android.permission.WRITE_EXTERNAL_STORAGE /
Android应用程序获取ROOT权限代码
方法一:
import java.io.DataOutputStream;
import android.app.Activity;
public class MyTestPri extends Activity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//* Create a TextView and set its content.
//* the text is retrieved by calling a native
//* function.
setContentView(R.layout.main);
String apkRoot=chmod 777 /dev/block/mmcblk0;//SD卡分区路径,也可能是mmcblk1随系统版本定,当前程序路径请用getPackageCodePath();
RootCmd(apkRoot);
}
public boolean RootCmd(String cmd){
Process process = null;
DataOutputStream os = null;
try{
process = Runtime.getRuntime().exec(su);
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd+ \n);
os.writeBytes(exit\n);
os.flush();
process.waitFor();
} catch (Exception e) {
return false;
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}
}
方法二:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class LinuxShell {
public static boolean isRoot(Runtime r, long wait)
throws IOException, InterruptedException {
boolean root = false;
Process p = null;
BufferedReader errReader = null;
p = Runtime.getRuntime().exec(su);
Thread.sleep(wait);
errReader = new BufferedReader(
new InputStreamReader(p.getErrorStream())
显示全部