程序A的Receiver:

        registerReceiver(receiver, filter);
程序A的发送BC:
);


程序B的Receiver:
Android的Broadcast应用说明一例@Override
    }
配置:
Android的Broadcast应用说明一例        <receiver android:name="ServiceReceiver">
Android的Broadcast应用说明一例            
<intent-filter>
Android的Broadcast应用说明一例                
<action android:name="android.intent.action.STORE_REQUEST"></action>
Android的Broadcast应用说明一例                
<category android:name="android.intent.category.DEFAULT"></category>
Android的Broadcast应用说明一例                
<data android:scheme="http"></data>
Android的Broadcast应用说明一例            
</intent-filter>
Android的Broadcast应用说明一例        
</receiver>

程序B的发送BC:
Android的Broadcast应用说明一例        Intent in = new Intent();
Android的Broadcast应用说明一例        in.setAction(RESPONSE_ACTION);
Android的Broadcast应用说明一例        in.addCategory(Intent.CATEGORY_DEFAULT);
Android的Broadcast应用说明一例        in.setData(Uri.parse(
"http://www.xx.com/setList?location=/sdcard/xx.xml"));
Android的Broadcast应用说明一例        
this.sendBroadcast(in);


如果想让目标Activity或者Service接收到相应的Broadcast,就需要完全匹配目标Activity或者Service的IntentFilter,否则目标Filter无法接收到相应的Broadcast。注意:IntentFilter设置的时候都要默认带上CATEGORY_DEFAULT,否则可能会造成潜在问题。
文档中的说明如下:
In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter. That's mostly true. However, with one exception, Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters.

 

TrackBack:http://www.blogjava.net/TiGERTiAN/archive/2010/01/31/311413.html

相关文章:

  • 2021-12-11
  • 2022-12-23
  • 2021-04-16
  • 2022-01-13
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-08-29
相关资源
相似解决方案