以编程方式将资产文件夹中的apk文件保存到android中的系统/应用程序 [英] Programatically save apk file from asset folder to system/app in android

查看:32
本文介绍了以编程方式将资产文件夹中的apk文件保存到android中的系统/应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式将 apk 文件从资产文件夹保存到 android 中的系统/应用程序文件夹.

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());
    } 

请帮帮我.

谢谢!

推荐答案

除非您有权限,否则您不能写入 /system.为此,您需要一个有根设备.

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?

这篇关于以编程方式将资产文件夹中的apk文件保存到android中的系统/应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆