Reputation: 41749
How does CleanMaster app detect that a new app has been installed on the device? Whenever I install a new app, I get a popup asking if I want to move the app to SD card.
I am trying to code similar behaviour but cannot find a way to do it.
Upvotes: 0
Views: 943
Reputation: 14590
For this You need to write a receiver class like this
public class AppInstallReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
//Perform Your opeartion
}
}
And register it in manifest like.
<receiver android:name="com.example.AppInstallReceiver" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Upvotes: 1
Reputation: 1559
Android provides String android.content.Intent.ACTION_PACKAGE_ADDED ="android.intent.action.PACKAGE_ADDED"
Broadcast Action: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.
You can write a BroadcastReceiver
receiving the Intent.ACTION_PACKAGE_ADDED
for that.
Upvotes: 1
Reputation: 6108
There is the ACTION_PACKAGE_ADDED Broadcast Intent, but the application being installed doesn't receive this.
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
Upvotes: 4