Programatically save apk file from asset folder to system/app in android

时光总嘲笑我的痴心妄想 提交于 2019-12-10 12:14:08

问题


I am trying to programatically save apk file from asset folder to system/app folder in android.

I am using following code. but error is showing read only file system.

AssetManager assetManager = getAssets();
    InputStream in = null;
    OutputStream out = null;
    try {
        in = assetManager.open("youtuberanjit.apk");
        out = new FileOutputStream("/system/app/youtuberanjit.apk");
        byte[] buffer = new byte[1024];
        int read;
        while((read = in.read(buffer)) != -1){
            out.write(buffer, 0, read);
        }
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(
                Uri.fromFile(new File("/system/app/youtuberanjit.apk")), "application/vnd.android.package-archive");
        startActivity(intent);
    }catch(Exception e){
        // deal with copying problem
        Log.e("ERRORR", ""+e.getMessage());
    } 

Please help me.

Thank you!


回答1:


You cannot write to /system unless you have rights to do that. You will need a rooted device for that.

Why do you want it to be a system app, and not a 'normal' user app?



来源:https://stackoverflow.com/questions/12674535/programatically-save-apk-file-from-asset-folder-to-system-app-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!