`
yidongkaifa
  • 浏览: 4060027 次
文章分类
社区版块
存档分类
最新评论

Android如何一次安装多个apk

 
阅读更多
最近在设计android 插件体系,遇到一个如何一次安装多个插件apk的问题,由于不能用root权限,目前只找到下面一种办法


把你关联的apk放在 assets目录下面。代码如下,只是在安装关联apk的时候是显示安装的。

private File getAssetFile()
    {
        AssetManager asset = MainActivity.this.getAssets();
        try
        {
            InputStream is = asset.open("Zxing.apk");
            FileOutputStream fos = this.openFileOutput("plugin1.apk",
                    Context.MODE_PRIVATE + Context.MODE_WORLD_READABLE);
            byte[] buffer = new byte[1024];
            int len = 0;
            
            while ((len = is.read(buffer)) != -1)
            {
                fos.write(buffer, 0, len);
            }
            
            fos.flush();
            
            is.close();
            
            fos.close();
            
            return new File("Zxing.apk");
            
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    
    private void installApk(File file)
    {
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(Intent.ACTION_VIEW);
        String type = "android/vnd.android.package-archive";
        intent.setDataAndType(Uri.from(file), type);
        startActivity(intent);
    }

这种方法还是会出现多次安装的界面,用户体验不太好。
分享到:
评论
1 楼 klxh 2017-02-06  
     

相关推荐

Global site tag (gtag.js) - Google Analytics