LocalBroadcastManager在模拟器(4.4.2)上接收所有具有相同操作字符串的广播,但不在电话上接收(4.0.4)

时间:2014-06-07 20:10:39

标签: android broadcastreceiver

广播接收器:

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>

0 个答案:

没有答案