監(jiān)聽?wèi)?yīng)用安裝,升級(jí),卸載的廣播
public class AppStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Uri uri = intent.getData();
if ("android.intent.action.PACKAGE_ADDED".equals(action)) {
Toast.makeText(context, "有應(yīng)用被安裝:" + uri.toString(), Toast.LENGTH_SHORT).show();
} else if ("android.intent.action.PACKAGE_REPLACED".equals(action)) {
Toast.makeText(context, "有應(yīng)用被升級(jí)" + uri.toString(), Toast.LENGTH_SHORT).show();
} else if ("android.intent.action.PACKAGE_REMOVED".equals(action)) {
Toast.makeText(context, "有應(yīng)用被卸載" + uri.toString(), Toast.LENGTH_SHORT).show();
}
}
}
<receiver
android:name=".AppStateReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"></action>
<action android:name="android.intent.action.PACKAGE_REPLACED"></action>
<action android:name="android.intent.action.PACKAGE_REMOVED"></action>
<data android:scheme="package"></data>
</intent-filter>
</receiver>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者