0

Good day!

Are there some tools in Android SDK, that i can use to remove application from activity. In particular, i need activity method, that removes other application with the same app-name, but other package.

  • I think the only option available is an implicit intent to uninstall the package. http://stackoverflow.com/questions/7868460/implicit-intent-to-uninstall-application – DeeV Jul 01 '15 at 18:35

1 Answers1

0

If you mean with "same name app" to app with same label that define in XML menifest as the label of your app, this snippest should work:

private void deleteAppByActivityName(@NonNull String myAppLabel,@NonNull Context context){
  try {
      PackageManager pm = context.getPackageManager();
      Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
      mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
      List<ResolveInfo> dataInDevice = pm.queryIntentActivities(mainIntent, 0);
      for (ResolveInfo resolveInfo : dataInDevice){
          String label = resolveInfo.loadLabel(pm).toString();
          if (label.equals(myAppLabel)) { //we find app with same name as ours
              Intent intent = new Intent(Intent.ACTION_DELETE);
              intent.setData(Uri.parse("package:" + resolveInfo.activityInfo.packageName));
              context.startActivity(intent);
              break;
          }
      }
  }catch (ActivityNotFoundException e){
      e.printStackTrace();
  }

}

yshahak
  • 4,996
  • 1
  • 31
  • 37