android - 新应用安装的 BroadcastReceiver

标签 android package broadcastreceiver android-intent

我想在安装新应用程序时收到通知。

IntentFilter newAppFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
newAppFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
newAppFilter.addAction(Intent.ACTION_PACKAGE_INSTALL);
newAppFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
getApplicationContext().registerReceiver(newAppReceiver, newAppFilter);


public static BroadcastReceiver newAppReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {     
            Log.e("Broadcast","Received");
       }
};

但是我无法获取任何日志。谁能帮帮我?

最佳答案

尝试将数据方案添加到您的 IntentFilter

newAppFilter.addDataScheme("package");

引用:IntentFilter.addDataScheme()文档

If no schemes are included, then an Intent will match only if it includes no data.

关于android - 新应用安装的 BroadcastReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6213596/

相关文章:

android - 是否可以使用 AWS AppSync 构建离线优先的移动应用程序?

android - 在 LinearLayout 中放置 3 个按钮以占用相等的空间

scala - 关于 protected[some_scope] 和 scala 中继承工作的困惑

c - 如何在 Windows 上安装 C 包

android - 广播接收器没有收到额外的东西

java - android通知remoteview不显示

android - Android GridLayout中如何设置元素的列和行

android - 我发布的 Android 应用程序无法安装到来自 Android 市场的设备上

android - 如何在不以 Intent 启动 Activity 的情况下从在 list 中注册的广播接收器调用 Activity 中的方法?

android - 如何获取当前位置和去电摘机时间(确切的调用选择时间)?