安装APP
filePath 安装包的路径
public static boolean installNormal(Context context, String filePath) { Intent i = new Intent(Intent.ACTION_VIEW); java.io.File file = new java.io.File(filePath); if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) { return false; } i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive"); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); return true; }
卸载APP
packageName 包名
public static boolean uninstallNormal(Context context, String packageName) { if (packageName == null || packageName.length() == 0) { return false; } Intent i = new Intent(Intent.ACTION_DELETE, Uri.parse(new StringBuilder().append("package:") .append(packageName).toString())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); return true; }