2013-03-17 218 views
2

我想連接一個藍牙耳機到我的android設備使用android開發者頁面作爲參考。 http://developer.android.com/guide/topics/connectivity/bluetooth.htmlandroid藍牙耳機getprofileproxy返回null

我的問題是,當我試圖調用getProfileProxy(context,mProfileListener,BluetoothProfile.HEADSET)方法時,我不確定要傳遞的上下文是什麼?我從這裏的問題找到這個錯誤: can not connect to bluetooth headset in android

我對此非常新,所以我會提前道歉,如果這是一個愚蠢的問題。我花了很多時間去研究這個問題,但是我發現每個例子和文檔都只有一個上下文變量,所以我不知道我錯在哪裏。我的代碼,或多或少是來自android文檔的副本:

//建立到代理的連接。 boolean mProfileProxy = mBluetoothAdapter.getProfileProxy(context,mProfileListener,BluetoothProfile.HEADSET); Log.d(TAGP,「Get Adapter Success:」+ mProfileProxy); Log.d(TAGP,「Get Adapter Success:」+ mProfileProxy); Log.d(TAGP,「Context:」+ context);

BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { 
    public void onServiceConnected(int profile, BluetoothProfile proxy) { 
     if (profile == BluetoothProfile.HEADSET) { 
      mBluetoothHeadset = (BluetoothHeadset) proxy; 
      Log.d(TAGP,"BLuetooth Headset: "+mBluetoothHeadset); 
      Log.d(TAGP,"Proxy: "+proxy); 
     } 
    } 
    public void onServiceDisconnected(int profile) { 
     if (profile == BluetoothProfile.HEADSET) { 
      mBluetoothHeadset = null; 
     } 
    } 
}; 

回答