0

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

我正在使用以下代码。但错误显示只读文件系统。

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

请帮我。

谢谢!

4

1 回答 1

2

/system除非您有权这样做,否则您不能写信给。为此,您将需要一个有根设备。

为什么您希望它成为系统应用程序,而不是“普通”用户应用程序?

于 2012-10-01T14:25:12.847 回答