美文网首页
android的APP中用linux命令拷贝文件

android的APP中用linux命令拷贝文件

作者: MacLi | 来源:发表于2018-08-31 17:29 被阅读0次
    public void clickUpdate(View view) {
            Process process = null;
            DataOutputStream os = null;
            String fileName = "SystemUI.apk";
            String srcFilename = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName;
            String destFilename = "/system/priv-app/" + fileName;
            try {
                FileUtil.copyFileFromAssets(this, fileName, srcFilename);
                process = Runtime.getRuntime().exec("/system/xbin/su");
                os = new DataOutputStream(process.getOutputStream());
                os.writeBytes("mount -o remount /dev/block/by-name/system /system\n");
                os.writeBytes("rm -r " + destFilename + "\n");
                os.writeBytes("busybox cp -rf " + srcFilename + " " + destFilename + "\n");
                os.writeBytes("chmod 644 " + destFilename + "\n");
                os.writeBytes(" reboot \n");
                os.writeBytes(" exit \n");
                os.flush();
                process.waitFor();
                int ret = process.exitValue();
                Log.e(LOG_TAG, "exitValue = "+ret);
                if (ret == 0) {
                    mTV_status.setText("更新成功!请重启系统!");
                } else {
                    mTV_status.setText("更新失败!");
                }
            } catch (Exception e) {
                e.printStackTrace();
                mTV_status.setText("更新失败!");
            } finally {
                try {
                    if (os != null) {
                        os.close();
                    }
                    if (process != null) {
                        process.destroy();
                    }
                } catch (Exception e) {
                }
            }
        }
    

    相关文章

      网友评论

          本文标题:android的APP中用linux命令拷贝文件

          本文链接:https://www.haomeiwen.com/subject/fjlewftx.html