How to Programmatically Uninstall a Package in Android

install / uninstall APKs programmatically (PackageManager vs Intents)

This is not currently available to third party applications. Note that even using reflection or other tricks to access installPackage() will not help, because only system applications can use it. (This is because it is the low-level install mechanism, after the permissions have been approved by the user, so it is not safe for regular applications to have access to.)

Also the installPackage() function arguments have often changed between platform releases, so anything you do trying access it will fail on various other versions of the platform.

EDIT:

Also it is worth pointing out that this installerPackage was only added fairly recently to the platform (2.2?) and was originally not actually used for tracking who installed the app -- it is used by the platform to determine who to launch when reporting bugs with the app, for implementing Android Feedback. (This was also one of the times the API method arguments changed.) For at least a long while after it was introduced, Market still didn't use it to track the apps it has installed (and it may very well still not use it), but instead just used this to set the Android Feedback app (which was separate from Market) as the "owner" to take care of feedback.

Uninstall application programmatically Android 10

There is permission missing in Manifest please add this permission in manifest...

 <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"></uses-permission>

this will work...!!!

unistall android application programmatically

try

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:app package name"));
startActivity(intent);

If this doesn't work then
change intent to:

Intent.ACTION_UNINSTALL_PACKAGE); 

and set datatype as:

intent.setDataAndType(Uri.parse("package:" + your app package name));

How to uninstall apps in android programmatically with PackageInstaller

You can refer to this link

https://www.programcreek.com/java-api-examples/index.php?api=android.content.pm.PackageInstaller

and implement like this -

@Override
public void uninstall(String packageName, String callerPackageName, int flags, IntentSender statusReceiver, int userId) throws RemoteException {
boolean success = VAppManagerService.get().uninstallPackage(packageName);
if (statusReceiver != null) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME, packageName);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS, success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE, PackageHelper.deleteStatusToString(success));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS", success ? 1 : -1);
try {
statusReceiver.sendIntent(mContext, 0, fillIn, null, null);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}

Uninstall APKs programmatically for all user

    final Uri packageURI = Uri.parse("package:" + "package:com.example.mypackage");
final Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
uninstallIntent.putExtra("android.intent.extra.UNINSTALL_ALL_USERS", false or true);
startActivity(uninstallIntent);

You can check out this answer from where I've taken reference - Is there an intent for uninstallation of an app for ALL users?

What is mean by multiple user?

If you have a used laptop or machine, then you may already be familiar with the concept here: Where you can create multiple accounts with different roles. It’s like having multiple machines wrapped into one.

Android has a very similar feature built in called User Profiles. It will create a separate profiles where one can make changes and keep multiple settings. But yeah when users installs app it will automatically will be installed in all profiles so end user need manually uninstall it in the profile where it is not required.

I tried using this in my device but performance is bit slow after I added multiple profile.

How to uninstall an Android app programmatically without user interaction?

try this method on rooted device

    try{
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

outputStream.writeBytes("pm uninstall package_name\n");
outputStream.flush();

outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
}catch(IOException e){
throw new Exception(e);
}catch(InterruptedException e){
throw new Exception(e);
}


Related Topics



Leave a reply



Submit