0

I need to uninstall and reinstall an apk file, based on the latest version from the server. When I'm not updating my application in Google Play, how do I uninstall and reinstall the application? My code for uninstalling:

public void UnInstallApplication(String packageName)// Passing com.example.homelauncher as package name.
    {

        Uri packageURI = Uri.parse(packageName.toString());
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
        uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(uninstallIntent); 
    }

I get the following error:

08-05 20:07:29.670: E/AndroidRuntime(845): FATAL EXCEPTION: main
08-05 20:07:29.670: E/AndroidRuntime(845): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.DELETE dat=com.example.homelauncher flg=0x10000000 }
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.app.Activity.startActivityForResult(Activity.java:2827)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.app.Activity.startActivity(Activity.java:2933)
08-05 20:07:29.670: E/AndroidRuntime(845):  at com.example.homelauncher.MainActivity.UnInstallApplication(MainActivity.java:246)
08-05 20:07:29.670: E/AndroidRuntime(845):  at com.example.homelauncher.MainActivity$2$1.onClick(MainActivity.java:152)
08-05 20:07:29.670: E/AndroidRuntime(845):  at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.os.Looper.loop(Looper.java:123)
08-05 20:07:29.670: E/AndroidRuntime(845):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-05 20:07:29.670: E/AndroidRuntime(845):  at java.lang.reflect.Method.invokeNative(Native Method)
08-05 20:07:29.670: E/AndroidRuntime(845):  at java.lang.reflect.Method.invoke(Method.java:507)
08-05 20:07:29.670: E/AndroidRuntime(845):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-05 20:07:29.670: E/AndroidRuntime(845):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-05 20:07:29.670: E/AndroidRuntime(845):  at dalvik.system.NativeStart.main(Native Method)

Can anyone tell me how to do this without using Google Play?

Xynariz
  • 1,232
  • 1
  • 11
  • 28
Vinoth Kumar
  • 489
  • 3
  • 17
  • 45
  • 1
    In case it's that: "An app downloaded from Google Play may not modify, replace or update its own APK binary code using any method other than Google Play's update mechanism." (= your app might get removed) [via](http://techcrunch.com/2013/04/26/google-crashes-facebook-homes-easy-updating-party-now-requires-all-play-apps-to-be-updated-through-the-play-store/) – zapl Aug 05 '13 at 15:09

2 Answers2

1

You're forming your URI incorrectly. See this SO post for a related question (almost a duplicate). I've copied the relevant detail below: essentially you need to use the following code to construct the URI for the intent method to work.

Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
getPackageManager().getPackageArchiveInfo(apkUri.getPath(), 0).packageName,null));
startActivity(intent);
Community
  • 1
  • 1
Chris Thompson
  • 35,167
  • 12
  • 80
  • 109
0

if your device is rootet, you can uninstall a apk using adb commands executed in the Android Linux shell.

String command = "pm uninstall com.my.first.program ";