标签:context extend cas nbsp end filter 文件中 androi 方法
一、创建一个类继承BroadcastReceiver并且复写onReceive的方法
public class AppStateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if ("android.intent.action.PACKAGE_ADDED".equals(action)) { Toast.makeText(context, "应用被安装了", Toast.LENGTH_SHORT).show(); } else if ("android.intent.action.PACKAGE_REMOVED".equals(action)) { //获取被卸载的包名 Uri data = intent.getData(); String pac = data.toString(); Toast.makeText(context, pac, Toast.LENGTH_SHORT).show(); Toast.makeText(context, "应用被卸载了", Toast.LENGTH_SHORT).show(); } } }
二、在AndroidManifest.xml文件中配置如下:
<receiver android:name=".AppStateReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED"/> <action android:name="android.intent.action.PACKAGE_REMOVED"/> <data android:scheme="package"/> </intent-filter> </receiver>
标签:context extend cas nbsp end filter 文件中 androi 方法
原文地址:http://www.cnblogs.com/doitbyyourself/p/6256829.html