2

I want to be able to allow my users to uninstall application from my application. Just like what Google Play Store allow to their users(Please below image)

enter image description here

the main question is that how can define a button that by pressing it we can uninstall an app by giving the package name or some other info.Just like the uninstall button on the image.

Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115
  • 1
    have a look thia Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE); intent.setDataAndType(Uri.parse("package:" + app_pkg_name)); startActivity(intent); – Naveen Tamrakar Dec 08 '14 at 13:07

3 Answers3

6

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));
RonTLV
  • 2,376
  • 2
  • 24
  • 38
Harry Sharma
  • 2,190
  • 2
  • 15
  • 41
0

Try this:

Intent intent = null;
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
    intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
} else {
    intent = new Intent(Intent.ACTION_DELETE);
}

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.fromParts("package", packageName, null));
if(intent.resolveActivity(getActivity( ).getPackageManager()) != null) {
    startActivity(intent);
}
RonTLV
  • 2,376
  • 2
  • 24
  • 38
KR_Android
  • 1,149
  • 9
  • 19
0

kotlin // This is for kotlin

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

Code

val intent = Intent(Intent.ACTION_DELETE)
intent.data = Uri.parse("package:"+app_package_name)
startActivity(intent)
// note app package name should be given properly.
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
  • It's good practice to put code or expression in quotes \` like ``. Code is much easier to read and eye-catch – Krystian Kaniowski Aug 31 '21 at 10:57
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Aug 31 '21 at 10:58
  • This is very similar to the solution in the accepted answer. When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers. – Eric Aya Aug 31 '21 at 11:33