如何捕捉或者接收的Android OS“广播”安装的应用程序? [英] How to catch or receive android os ' broadcasts' of installed applications?
本文介绍了如何捕捉或者接收的Android OS“广播”安装的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想收到的机器人安装的应用程序播放。会是什么程序?
I want to receive broadcasts of android installed applications. What would be the procedure ?
推荐答案
您可以注册广播意图 Intent.ACTION_PACKAGE_ADDED
(和/或意图。 ACTION_PACKAGE_REMOVED
, Intent.ACTION_PACKAGE_CHANGED
如果需要的话)。
You can register Broadcast intent Intent.ACTION_PACKAGE_ADDED
( and/or Intent.ACTION_PACKAGE_REMOVED
, Intent.ACTION_PACKAGE_CHANGED
if needed).
code是类似以下内容:
Code is something like following:
void registerReceiver() {
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addDataScheme("package");
...
}
public void onReceive(Context context, Intent intent) {
String actionStr = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(actionStr)) {
Uri data = intent.getData();
String pkgName = data.getEncodedSchemeSpecificPart();
//handle package adding...
...
}
}
这篇关于如何捕捉或者接收的Android OS“广播”安装的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文