tags:

views:

320

answers:

1

I am trying to register a Broadcast Receiver to receive broadcast events for the package events. Following is the code and my receiver in the manifest file. The log statment never happens, but I can clearly see the same broadcast firing for "HomeLoaders" (the Launcher) debug statements. Could someone explain what I am missing?

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>
A: 

It is possible that these Intents cannot be received by components registered in the manifest, but only by receivers registered in Java via registerReceiver().

CommonsWare
Yea im pretty sure thats the case, out of curiosity why is this the case? I don't see any security implications of this?
Faisal Abid
As I commented on another SO question a day or so ago, Android does not necessarily want to start up a new component all of the time. The one case I knew of was for battery events (e.g., ACTION_BATTERY_LOW). It looks like SCREEN_OFF (and maybe SCREEN_ON) are others. If you think of it, and you get it working with registerReceiver(), chime back on this issue. I think I need to cover this topic in a blog post and/or book section, and unfortunately the list of no-manifest-receiver Intents is undocumented.
CommonsWare
I would like to see where this is documented. I have inspected the source and the only check against these protected broadcasts is so a non system process cannot initiate a broadcast. I have also seen other packages in the source register for this intent through the manifest only.
James