-1

Am trying to uninstall application from my application using the below code

     try
     {
         Log.e ( TAG, " Going to clear the application with startactivity alone  " );;
         Uri packageURI = Uri.parse("package:"+"com.example.canvas");
         Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageURI);
         //uninstallIntent.putExtra(Intent.EXTRA_UNINSTALL_ALL_USERS, allUsers);
         startActivityForResult(uninstallIntent, REQUEST_UNINSTALL);
         Log.e ( TAG, " Cleared the applicaiton " );
     }
     catch ( Exception e )
     {
         String data = e.getMessage();
         Log.e ( TAG, " data " + data );
     }

But am getting an execption and the exception says

09-26 16:16:52.519: E/FActory reset(17246):  data No Activity found to handle Intent { act=android.intent.action.UNINSTALL_PACKAGE dat=package:com.example.canvas } 
Aswin
  • 1
  • Are you sure this package is present? Also this link may help you http://stackoverflow.com/questions/7868460/implicit-intent-to-uninstall-application – Ajit Pratap Singh Sep 26 '14 at 10:56
  • Thanks Ajit, i was running this in a old version. that's the issue, Running in a jelly bean and it's running fine. But its launching an acitivity, i don't want any acitivity to launch, just uninstall APK at the background – Aswin Sep 26 '14 at 11:09
  • AFAIK that would not be possible.It will always open the uninstall wizard – Ajit Pratap Singh Sep 26 '14 at 11:10
  • Is there no way to do it Ajit ? – Aswin Sep 26 '14 at 11:23

2 Answers2

0

Use startActivity()

Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.canvas"));
startActivity(intent);

and also make sure that the package is installed on your device.

Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
0

Instead startActivityForResult() use startActivity() Like this

 Uri packageUri = Uri.parse("package:com.example.canvas");
     Intent uninstallIntent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri);
     startActivity(uninstallIntent);

make sure that your package com.example.canvas is installed in your device.

Kavin Prabhu
  • 2,307
  • 2
  • 17
  • 36
  • its opening an activity, but i want to do it in the background with out interrupting user – Aswin Sep 26 '14 at 11:23
  • No it won't open activity. It will show pop-up for user authentication to uninstall the application. **Note: You cannot uninstall any application without user authentication.** – Kavin Prabhu Sep 26 '14 at 11:32
  • Thanks kevin, FYI : When went through the ASOP, i found that the user authentication is even an activity. – Aswin Sep 26 '14 at 12:22
  • Sorry, maybe you referring old version of android. I referred 4.4.4 in that it won't open activity. It will just show alert dialog for user authentication. By the way if my answer helps you vote it up! Thank you :) – Kavin Prabhu Sep 26 '14 at 12:38