卸载
public void UninstallApk(String appPackage){
Log.d(TAG, "uninstall:" + appPackage);
Intent pendIntent = new Intent(mContext, mContext.getClass());
PendingIntent sender = PendingIntent.getActivity(mContext, 0, pendIntent, 0);
PackageInstaller mPackageInstaller = mContext.getPackageManager().getPackageInstaller();
if (isAppInstalled(mContext, appPackage)) {
mPackageInstaller.uninstall(appPackage, sender.getIntentSender());
} else {
Log.d(TAG, appPackage + "is not exist!!");
}
}
安装
public void installApp(String appAbsPath){
IPackageManager mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
Log.d(TAG, "install: " + appAbsPath);
File apkFile = new File(appAbsPath);
try {
mPm.installPackageAsUser(Uri.fromFile(apkFile).getPath(), null, 2, apkFile.getName(), mContext.getUserId());
} catch (RemoteException e) {
e.printStackTrace();
}
}