【问题标题】:BroadcastReceiver on new app installs新应用安装的广播接收器
【发布时间】:2011-09-07 00:02:27
【问题描述】:

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

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");
       }
};

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

【问题讨论】:

    标签: android package broadcastreceiver android-intent


    【解决方案1】:

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

    newAppFilter.addDataScheme("package");
    

    参考:IntentFilter.addDataScheme() 文档

    如果不包括任何方案,则 仅当它包含 Intent 时才会匹配 没有数据。

    【讨论】:

      【解决方案2】:

      如果有人遇到此问题,则意图文档现在显示:
      ACTION_PACKAGE_INSTALL - This constant is deprecated. This constant has never been used.

      【讨论】:

        猜你喜欢
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-17
        • 1970-01-01
        相关资源
        最近更新 更多