获取ROOT并修改mmcblk0分区权限为777:
点击(此处)折叠或打开
- 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;
- }
- }
执行完成后,可以看到该设备权限已被修改为777,注:如果只是想按照扇区读写SD卡,修改为606就足够了,或者再尝试低一点的权限。