广播接收器:
public class OrderReceiver extends BroadcastReceiver {
onReceive(Context mContext, Intent intent) {
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")) {
//reference 1
//do some work
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(mContext);
intent.setAction("com.gndp.message.RECEIVED");
lbm.sendBroadcast(intent);
}
else if (action.equals("com.google.android.c2dm.intent.RECEIVE")) {
//reference 2
//do some work
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(mContext);
intent.setAction("com.gndp.message.RECEIVED");
lbm.sendBroadcast(intent);
}
}
内部活动:
onCreate(){
BroadcastReceiver deviceRegisteredBroadcastReciever = new BroadcastReceiver() {
onReceive(Context context, Intent intent) {
//reference 3
if(intent.getStringExtra("data1")==null){
//code 1
}
else{
//code 2
}
}
}
onResume(){
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(mContext);
lbm.registerReceiver(deviceRegisteredBroadcastReciever, new IntentFilter("com.gndp.message.RECEIVED"));
}
在模拟器上,代码到达:
参考1 ------>参考3
和
参考2 ------>参考3
但在设备上,代码到达:
参考1 ------>参考3
和
参考2 --- X --->参考3(它到达参考文献2但是在参考文献3中没有收到广播)
并且logcat中没有错误。这是我的androidManifest.xml:
<receiver
android:name="com.gndp.OrderReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.gndp" />
</intent-filter>
</receiver>