jac*_*ast 0 android android-intent android-launcher
我正在开发一个启动器应用程序,我刚刚添加了一个广播接收器,我将使用它来更新应用程序列表。我最初尝试接收ACTION_PACKAGE_ADDED,ACTION_PACKAGE_REMOVED因为它们似乎足以胜任这项工作,但没有一个被解雇,所以我添加了我认为有用的所有其他与包相关的操作,并尝试在活动中注册它们:
val intentFilter = IntentFilter()
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED)
intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED)
intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL)
intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED)
val rec = AppsInstallationsReceiver()
registerReceiver(rec, intentFilter)
Run Code Online (Sandbox Code Playgroud)
并体现:
<receiver android:name=".core.installed_apps.AppsInstallationsReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
接收器本身没什么特别的:
class AppsInstallationsReceiver : BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
//TODO
}
}
Run Code Online (Sandbox Code Playgroud)
事实证明,我只收到PACKAGE_FULLY_REMOVED并且仅当它在清单中注册时才收到。现在这已经足够好了,但我需要一种方法来知道何时安装新应用程序。由于这是一个启动器应用程序,因此此功能至关重要。为什么我没有收到任何东西?当然,该活动仍然存在于后台,因为它被用作启动器。
| 归档时间: |
|
| 查看次数: |
1006 次 |
| 最近记录: |