发送广播而且接受。发送两个广播
Intent intent = new Intent(); intent.setAction("com.wxq.CUSTOM_INTENT"); sendBroadcast(intent); intent.setAction("com.wxq.test2"); sendBroadcast(intent);
接收方
@Override public void onReceive(Context context, Intent intent) { String intentName = "com.wxq.CUSTOM_INTENT"; String intentName2 = "com.wxq.test2"; if(intent.getAction().equals(intentName)) Toast.makeText(context, intentName+"Intent Detected", Toast.LENGTH_LONG).show(); else if(intent.getAction().equals(intentName2)) Toast.makeText(context, intentName2+"Intent Detected", Toast.LENGTH_LONG).show(); }AndroidMini中
增加receiver以及过滤
<receiver android:name="MyReceiverTest" >
<intent-filter>
<action android:name="com.wxq.CUSTOM_INTENT" >
</action>
</intent-filter>
<intent-filter>
<action android:name="com.wxq.test2" >
</action>
</intent-filter>
</receiver>