I have a Broadcastreceiver to detect other apps installs or deletion.
This is my Java
public class AppListener extends BroadcastReceiver {
@Override
public void onReceive(Context var1, Intent var2) {
// TODO Auto-generated method stub
Log.d("AppTag", "Received!");
}
}
This is my manifest
<receiver android:name=".AppListener">
<intent-filter android:priority="999">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
But whenever I install or delete an app nothing occurs!
You are trying to listen to broadcasts like ACTION_PACKAGE_ADDED
and ACTION_PACKAGE_REPLACED
. That is fine for Android 7.1 and lower. On Android 8.0+, you cannot register for those broadcasts in the manifest, as most implicit broadcasts are banned.
Instead, you need to call getChangedPackages()
on PackageManager
periodically, such as via WorkManager
. This will not give you real-time results, but real-time results are no longer an option on Android 8.0+.