安装APK文件

方法一:传入File文件

    public void installApp(File file) {        try {            Intent intent = new Intent();            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            intent.setAction(android.content.Intent.ACTION_VIEW);            String type = "application/vnd.android.package-archive";            intent.setDataAndType(Uri.fromFile(file), type);            startActivity(intent);        } catch (Exception e) {            e.printStackTrace();        }    }

方法二:传入文件名称

    public void installApp(String file_name) {        try {            Intent intent = new Intent();            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);            intent.setAction(android.content.Intent.ACTION_VIEW);            String type = "application/vnd.android.package-archive";            intent.setDataAndType(Uri.parse(file_name), type);            startActivity(intent);        } catch (Exception e) {            e.printStackTrace();        }    }



卸载APK

    Uri uri = Uri.parse("package:com.xxx.xxx");       Intent intent = new Intent(Intent.ACTION_DELETE, uri);       startActivity(intent);
Uri解析的内容必须为“package:包名”,利用ACTION_DELETE动作和Uri数据,就可以卸载了。


在安装和卸载时,并不需要另外在AndroidManifest.xml文件添加权限。


更多相关文章

  1. android aidl文件分析
  2. 在Mac上完全删除android studio初始配置文件
  3. Android中几种延后处理事件的方法
  4. Android判断包名和类名是否存在的方法
  5. Android SDK 1.5 "--core-library" build error问题解决方法
  6. android http通信(二) 英译汉字典实例探究网络通信三种方法
  7. android sdk content loader 加载很慢的解决方法
  8. android 开发中的文件操作

随机推荐

  1. Android(安卓)Layout XML属性研究--andro
  2. android 添加文件打开方式,找了很久终于找
  3. Android面试系列文章2018之Android部分Se
  4. Permissions
  5. android:configChanges属性,横竖屏切换
  6. Android布局控件属性
  7. 【转载】【Android】Android(安卓)Camera
  8. android带有文字的图片按钮的两种实现方
  9. android 中 焦点控制
  10. This Android(安卓)SDK requires And...t