美文网首页
Android代码实现安装、卸载、打开

Android代码实现安装、卸载、打开

作者: 幽兰清风 | 来源:发表于2017-06-07 19:30 被阅读82次

    安装:

      String str = "/CanavaCancel.apk";
      String fileName = Environment.getExternalStorageDirectory() + str;
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
      startActivity(intent); 
    

    卸载:

      Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");
      Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
      startActivity(uninstallIntent);
    

    打开:

      String str = "/CanavaCancel.apk";
      String file = Environment.getExternalStorageDirectory() + str;
      Intent intent = new Intent();
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setAction(android.content.Intent.ACTION_VIEW);
      intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
      startActivity(intent);

    相关文章

      网友评论

          本文标题:Android代码实现安装、卸载、打开

          本文链接:https://www.haomeiwen.com/subject/pvuafxtx.html