pixel
pixel

Reputation: 26441

Callback after my application was installed?

Is there any callback / receiver / anything that gets called once when my application is installed?

Upvotes: 2

Views: 3681

Answers (2)

Ajay S
Ajay S

Reputation: 48592

For this, you have to make one application apart from your main application that can keep tracking about the install or uninstalled application from your device.

For this you need to register the Receiver.

<receiver android:name=".AppStatusReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
    </intent-filter>
</receiver>

AppStatusReceiver.java

public class AppStatusReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "Intent: " + intent.getAction());
    }
}

Note : If you are looking this to be manage from your main application callback then it is no possible.

Upvotes: 6

FD_
FD_

Reputation: 12919

There is no way for an app to run code when it was installed.

For other apps, you could create a BroadcastReceiver for ACTION_PACKAGE_ADDED, but as the docs explain, this won't work for the app that was newly installed:

Note that the newly installed package does not receive this broadcast.

Upvotes: 1

Related Questions