代码之家  ›  专栏  ›  技术社区  ›  James

无法接收包意图的广播

  •  5
  • James  · 技术社区  · 16 年前

    我正在尝试注册广播接收器以接收包事件的广播事件。下面是清单文件中的代码和我的接收者。日志状态从未发生过,但我可以清楚地看到“HomeLoaders”(启动程序)调试语句的相同广播触发。我错过了什么?

    public class IntentListener extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            Log.i("INTENT LISTNER:", intent.getAction());
        }
    }
    
    <receiver android:name="IntentListener" android:enabled="true" android:exported="true">
        <intent-filter>
            <data android:scheme="package"></data>
            <action android:name="android.intent.action.PACKAGE_ADDED"></action>
            <action android:name="android.intent.action.PACKAGE_ADDED"></action>
            <action android:name="android.intent.action.PACKAGE_CHANGED"></action>
        </intent-filter>
    </receiver>
    
    3 回复  |  直到 13 年前
        1
  •  4
  •   CommonsWare    16 年前

    有可能这些 Intent 在清单中注册的组件不能接收,而只能通过在Java中注册的接收器接收 registerReceiver()

        2
  •  0
  •   user936414    13 年前

    Intent.ACTION_PACKAGE_ADDED
    Intent.ACTION_PACKAGE_REMOVED
    Intent.ACTION_PACKAGE_CHANGED
    

    Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
    

    添加的标志,以便只有注册的接收器将接收广播,并且不会启动任何广播接收器组件。有关更多详细信息,请参阅Intent和PackageManagerService类。

        3
  •  0
  •   Peter Mortensen Pieter Jan Bonestroo    13 年前

    这是我的舱单,没有

    <category android:name="android.intent.category.DEFAULT" />
    

    Android Market 安装应用程序,但不删除。现在它还接收非安卓市场应用程序广播。

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".SomeActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <receiver android:name="com.som.pakage.PackageInstallReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
    
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="package" />
            </intent-filter>
        </receiver>
    </application>