Android - How to intercept the 'Install application' intent
Asked Answered
I

2

16

OK, so not entirely sure this is possible...

But trying to write an application so that I can run some code before any of the following activities are performed.

1) APK is downloaded from web and market launches installer

2) Install button is pressed on android market

Is it possible to intercept and prompt on these events, or has Google locked that stuff down quite tightly?

Interphase answered 18/8, 2010 at 9:15 Comment(0)
O
11

This isn't an answer per se, but I can't find any commenting tool here. Sorry. I'm having this issue as well. I would like to be able to detect new application installs. I know it is possible - for example, the app Apps to SD posts a notification when you install a new app that when clicked opens a dialog to move that new app to the sd card. So far, all I've been able to figure is like this: manifest.xml:

...
<receiver android:name=".IntentReceiver">
  <intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED" />
    <action android:name="android.intent.action.PACKAGE_REMOVED" />
    <data android:scheme="package" />
  </intent-filter>
</receiver>
...

IntentReciever.java:

public class IntentReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    context.startService(new Intent(context, YourService.class));
  }
}

YourService is then created and calls onCreate() then onStartCommand(). However, I haven't been able to debug this or successfully display any notifications from the service class, so I'm not entirely sure this works. I have gotten this to work for other Receivers like android.intent.action.BOOT_COMPLETED.

Outshout answered 10/9, 2010 at 14:34 Comment(1)
I added PACKAGE_REMOVED and the <data /> tag. Once those were in my manifest, my application correctly reported when any app was installed or removed. Please see: groups.google.com/group/android-developers/browse_thread/thread/… and developer.android.com/guide/appendix/faq/framework.html#7Outshout
T
5

Using a BroadcastReceiver you can filter the android.intent.action.PACKAGE_ADDED intent. However this will only be after the two actions you describe, not before. And it will not stop or interrupt the installation.

AFAIK there is no way to do anything before or to interrupt the Market. And then we're even talking about another app than the one that's being installed ofcourse.

Twickenham answered 26/9, 2010 at 18:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.