Android代码通过包名调用系统卸载程序

/**
 * 卸载指定包名的应用
 * @param packageName
 */
public boolean uninstall(String packageName) {
    boolean b = checkApplication(packageName);
    Logger.d(TAG, "Test:check:"+b);
    if (b) {
        Uri packageURI = Uri.parse("package:".concat(packageName));
        Intent intent = new Intent(Intent.ACTION_DELETE);
        intent.setData(packageURI);
        startActivity(intent);
        return true;
    }
    return false;
}

/**
 * 判断该包名的应用是否安装
 *
 * @param packageName
 * @return
 */
private boolean checkApplication(String packageName) {
    Logger.d(TAG, "Test,run");
    if (packageName == null || "".equals(packageName)) {
        return false;
    }
    try {
        getPackageManager().getApplicationInfo(packageName,
                PackageManager.MATCH_UNINSTALLED_PACKAGES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        Logger.e(TAG, "Test:"+e.toString());
    }
    return false;
}

你可能感兴趣的:(Android,android,卸载应用)