Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:10:54+00:00 2026-06-16T15:10:54+00:00

From my Application I am trying to uninstalling an application by using the code

  • 0

From my Application I am trying to uninstalling an application by using the code

Intent uninstallIntent = new Intent(Intent.ACTION_DELETE);
uninstallIntent.setData(Uri.parse("package:" +packageName));
uninstallIntent.setAction(Intent.ACTION_VIEW);
startActivityForResult(uninstallIntent,UNINSTALL_APPLICATION);

as per I am starting the activity for result I want to perform different actions on the basis of user’s input like if cancelled or clicked on ok.

As I expected the result code of clicking ok will be RESULT_OK and clicking on cancel will be RESULT_CANCEL, but in actual in both cases I am getting RESULT_CANCEL.

So how can I differentiate the user’s input.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:10:55+00:00Added an answer on June 16, 2026 at 3:10 pm

    After a lot of thoughts in mind finally i have got the solution tricky one.

    How I Implemented at the time of calling the Uninstall Intent i have saved the package name in a preferences file by using

    SharedPreferences prefs;
    prefs.edit().putString(DELETE_PACKAGE_NAME, packageName).commit();
    

    And what i have done in OnActivityresult i have just checked whether the application with saved package name still present if it is means user has clicked on Cancel else he clicked Ok.

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data); 
    
     if(requestCode==DELETE_APP){
    
        String requestedPackageName=prefs.getString(DELETE_PACKAGE_NAME, "");
    
        boolean isPresent=GCMIntentService.isAppPresent(requestedPackageName, this);
    
        if(isPresent){
    
          //user Clicked on Cancel
        }else{
    
          //user Clicked on Ok
        }
    
    
     }
    
    }
    

    Code for Checking the application presence

    public static boolean  isAppPresent(String packageName,Context context) {
    
    
      try{
        ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, 0 );
        return true;
    
    } catch( PackageManager.NameNotFoundException e ){
    
       return false;
    }
    
     }
    

    Thanks.

    UPDATED:

    As platform changed a lot since I answered this here is the update

    Now you can use an intent where you can explicitly define whether it should return a result or not

    val intent = Intent(Intent.ACTION_UNINSTALL_PACKAGE).apply {
                data = Uri.parse("package:$packageName")
                putExtra(Intent.EXTRA_RETURN_RESULT, true)
            }
            startActivityForResult(intent, YOUR_REQUEST_CODE_HERE)
    

    Documentation : https://developer.android.com/reference/android/content/Intent.html#ACTION_UNINSTALL_PACKAGE

    This will return a result a

    From the documentation :

    The returned result code will be Activity.RESULT_OK on success or
    Activity.RESULT_FIRST_USER on failure.

    Starting API 21 Android added a helper method

    PackageInstaller.uninstall (String packageName, 
                    IntentSender statusReceiver)
    

    Read more about the changes in the link below, stating from Android Q the above updated approach is also deprecated.

    https://developer.android.com/reference/android/content/pm/PackageInstaller.html#uninstall(java.lang.String,%20android.content.IntentSender)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from my application i'm trying to open another one, using this code: package com.copag.lanceappli;
Im trying to create application from scratch. In new maven project i add a
I am trying to send sms from java application using SMPPSim as SMS gateway
I am trying to convert an application I support from application.cfm to application.cfc. I
I am trying to port an application from Windows to Linux. In Windows I
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying to build an application from source in windows that requires some Unix
I'm trying to launch another application from C# application, is there a way to
I'm trying to migrate my application from the old App Engine db to ndb.
I'm trying to upgrade my Node application from 0.4 to 0.6 along with all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.