关于/dev/graphics/fb0拒绝访问的解决方案

来源:互联网 发布:鹏博士数据 编辑:程序博客网 时间:2024/06/08 03:22

关于/dev/graphics/fb0拒绝访问的解决方案

访问该路径时若出现以下log:
W/System.err﹕ Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
08-29 11:26:01.759 1188-1314/com.markslin.viewtest W/System.err﹕ at libcore.io.Posix.open(Native Method)
08-29 11:26:01.759 1188-1314/com.markslin.viewtest W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
08-29 11:26:01.763 1188-1314/com.markslin.viewtest W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:400)

解决方案一:
通过cmd进入控制台,输入以下命令即可:adb shell chmod 777 /dev/graphics/fb0

解决方案二:
由于安装到手机上用户不可能去输入命令,因此可采用以下方案,编写代码执行Linux命令

public void execLinuxCmd(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) {            e.printStackTrace();        }finally {            if (os!=null){                try {                    os.close();                    process.destroy();                } catch (IOException e) {                    e.printStackTrace();                }            }        }    }

以下是MainActivity仅供参考

public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        execLinuxCmd("chmod 777 /dev/graphics/fb0");    }    public void execLinuxCmd(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) {            e.printStackTrace();        } finally {            if (os != null) {                try {                    os.close();                    process.destroy();                } catch (IOException e) {                    e.printStackTrace();                }            }        }    }    public void testButtonClicked(View view) {        new Thread() {            @Override            public void run() {                super.run();                FileInputStream fileInputStream = null;                try {                    fileInputStream = new                     FileInputStream("/dev/graphics/fb0");                          if (fileInputStream == null)                        Log.i("RUN", "run null");                    else                        Log.i("RUN", "not null");                } catch (FileNotFoundException e) {                    e.printStackTrace();                } finally {                    if (fileInputStream != null)                        try {                            fileInputStream.close();                        } catch (IOException e) {                            e.printStackTrace();                        }                }            }        }.start();    }}

注:网上说在AndroidManifest.xml要配置什么android:sharedUserId,各种权限什么的。但是亲测如果只是访问该文件的话是不需要加任何东西的,也不需要什么源码命令,什么mm命令。如有出错请见谅。

0 0
原创粉丝点击