【问题标题】:How to catch or receive android os ' broadcasts' of installed applications?如何捕获或接收已安装应用程序的 android os '广播'?
【发布时间】:2011-07-16 11:36:13
【问题描述】:

我想接收 android 安装应用程序的广播。程序是什么?

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以注册广播意图Intent.ACTION_PACKAGE_ADDED(和/或Intent.ACTION_PACKAGE_REMOVEDIntent.ACTION_PACKAGE_CHANGED,如果需要)。

    代码如下:

    void registerReceiver() {
        IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
        filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        filter.addDataScheme("package");
        ...
    }
    
    public void onReceive(Context context, Intent intent) {
        String actionStr = intent.getAction();
        if (Intent.ACTION_PACKAGE_ADDED.equals(actionStr)) {
            Uri data = intent.getData();
            String pkgName = data.getEncodedSchemeSpecificPart();
            //handle package adding...
        ...
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 2015-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多