[英]Android Broadcastreceiver for other apps install/delete not working
I have a Broadcastreceiver to detect other apps installs or deletion.我有一个广播接收器来检测其他应用程序的安装或删除。
This is my Java这是我的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
.您正在尝试收听
ACTION_PACKAGE_ADDED
和ACTION_PACKAGE_REPLACED
类的广播。 That is fine for Android 7.1 and lower.这适用于 Android 7.1 及更低版本。 On Android 8.0+, you cannot register for those broadcasts in the manifest, as most implicit broadcasts are banned .
在 Android 8.0+ 上,您无法在清单中注册这些广播,因为大多数隐式广播都被禁止。
Instead, you need to call getChangedPackages()
on PackageManager
periodically, such as via WorkManager
.相反,您需要定期在
PackageManager
上调用getChangedPackages()
,例如通过WorkManager
。 This will not give you real-time results, but real-time results are no longer an option on Android 8.0+.这不会为您提供实时结果,但在 Android 8.0+ 上不再提供实时结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.