简体   繁体   中英

Android Broadcastreceiver for other apps install/delete not working

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+.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM