[英]How to make broadcast receiver to listen event for particular app in android?
我正在开发一个包含应用程序列表的应用程序,当用户从显示给他的列表中单击特定应用程序时,他将定向到可以从该网站下载该应用程序以收听应用程序的网站。我在android menifest.xml中添加了广播接收器问题是广播接收器是否会在系统以及从我的应用程序中下载的任何应用程序都监听。我要广播接收器仅在打开和关闭我的应用程序时才应该监听来自应用程序的事件。
这是我的Java代码:-
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Check if the application is install or uninstall and display the message accordingly
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
// Application Install
Log.e("Package Added:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
Log.e("Package Removed:-", intent.getData().toString());
} else if (intent.getAction().equals("android.intent.action.PACKAGE_REPLACED")) {
Log.e("Package Replaced:-", intent.getData().toString());
}
}
}
这是我的xml代码:-
<receiver android:name=".Receiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_REMOVED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
kinldy帮我,我从一周开始尝试。
Intent
BroadcastReceiver
收到的Intent
的信息,您无法知道应用程序是否安装了该软件包。 从技术上讲,您的应用没有安装任何东西,系统会这样做(第三方应用没有特权安装其他应用)。
您将必须从Intent
数据中检查包名称,并将其与用户随您的应用下载的应用进行比较。 那是你所能做的最好的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.