Programatically install apk from assets folder in android

前端 未结 2 654
我在风中等你
我在风中等你 2020-12-08 18:01

I am trying to install apk programatically from assets folder but not success, Please help me. I am using following code for that. thank you.

Intent intent =         


        
2条回答
  •  醉话见心
    2020-12-08 18:37

    AssetManager assetManager = getAssets();
    
    InputStream in = null;
    OutputStream out = null;
    
    try {
        in = assetManager.open("myapk.apk");
        out = new FileOutputStream("/sdcard/myapk.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("/sdcard/myapk.apk")),
            "application/vnd.android.package-archive");
    
        startActivity(intent);
    
    } catch(Exception e) { }
    

提交回复
热议问题