2012-03-27 105 views
1

你能幫我找出爲什麼brodcast reciver的註冊返回null嗎? 這是代碼:註冊reciver過濾器,無法找到

ScoIntent = new IntentFilter(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); 
       sReceiver = new ScoReceiver(context, Tmp); 
       if (context.registerReceiver(sReceiver, ScoIntent) == null) { 
        Log("FBR.GetBlueConnect:Error", "Can not find receiver ACTION_CONNECTION_STATE_CHANGED"); 
        HFS.DisplayText("Can not connect to Bluetooth Headset, Please Exit", true); 
       } 

,這是reciver:

class ScoReceiver extends BroadcastReceiver {  
    public ScoReceiver(Context mcontext, Tools t){ 
    bContext = mcontext; 
    tools = t; 
} 
@Override 
public void onReceive(Context context, Intent arg1) { 
    tools.Log("ScoReceiver:onReceive", "In"); 

    //arg1 = new Intent(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); 
    String action = arg1.getAction(); 
    tools.Log("ScoReceiver:onReceive", ">>> Bluetooth SCO state changed !!! "); 
    if(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED.equals(action)) { 
     int status = arg1.getIntExtra(BluetoothHeadset.EXTRA_STATE, AudioManager.SCO_AUDIO_STATE_ERROR); 

}

回答

0

的javadoc說,

返回第一粘貼意圖發現匹配濾波器,如果沒有,則返回空值 。

這個接收器是否有粘性意圖?這裏有一個貼子,討論棍子和非粘性意圖之間的差別,

what is the difference between sendStickyBroadcast and sendBroadcast in Android

+0

我已閱讀本Java文檔,但在粥手這個[鏈接] |(HTTP:// developer.android.com/reference/android/bluetooth/BluetoothHeadset.html)是關於brodcast意圖不粘性,在ather函數中提到dirctly – 2012-03-27 16:41:49

+0

http://developer.android.com/reference/android/bluetooth/BluetoothHeadset.html in這:ACTION_CONNECTION_STATE_CHANGED – 2012-03-27 16:45:00

+0

我完全糊塗 – 2012-03-27 17:10:15