Android开发程序代码获取root权限

jopen 11年前

把apk放到/system/app文件夹下,作为系统项目,就可以保证项目有root的权http://限。

root权限的app可以申请很多一般用户无法申请的权限。

参考:点击打开链接

可以查看哪些权限是需要root才能申请的。

import java.io.DataOutputStream;    import java.io.IOException;        import android.app.Activity;    import android.os.Bundle;    import android.view.View;    import android.widget.Button;        public class MainActivity extends Activity {                @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_main);            Button open = (Button) findViewById(R.id.open);            Button close = (Button) findViewById(R.id.close);            open.setOnClickListener(new View.OnClickListener() {                @Override                public void onClick(View v) {                    try {                        CopyAppToSystem();                    } catch (IOException e) {                        // TODO Auto-generated catch block                        e.printStackTrace();                    }                }            });            close.setOnClickListener(new View.OnClickListener() {                @Override                public void onClick(View v) {                    RunAsRooter();                }            });        }                private void RunAsRooter()        {            try {                  Process process = Runtime.getRuntime().exec("su");                  process.waitFor();                } catch (IOException e) {                  e.printStackTrace();                } catch (InterruptedException e) {                  e.printStackTrace();                }        }                private void CopyAppToSystem() throws IOException        {            Process process = Runtime.getRuntime().exec("su");            DataOutputStream out = new DataOutputStream(process.getOutputStream());            out.writeBytes("mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system\n");            out.writeBytes("cat /sdcard/myApp.adk > /system/app/myApp.adk\n");            out.writeBytes("mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system\n");            out.writeBytes("exit\n");              out.flush();            try {                process.waitFor();            } catch (InterruptedException e) {                e.printStackTrace();            }        }    }