Android 台灣中文網
標題:
用Ken Yang 筆記: Android Bluetooth API範例去連結到裝置沒反應
[打印本頁]
作者:
softkk
時間:
2014-7-16 15:35
標題:
用Ken Yang 筆記: Android Bluetooth API範例去連結到裝置沒反應
程式段如下,驗證確定有進入要連結的裝置"U02AF021"段的try{...}內.
但一直看不到作者所述之欲配對請求畫面.(我是去搜尋與連接PC端藍牙)
我已卡此近兩週了,敬請諸位前輩們惠予指教. 謝謝!
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
// 當收尋到裝置時
if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
// 取得藍芽裝置這個物件
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// 判斷那個裝置是不是你要連結的裝置,根據藍芽裝置名稱判斷
if (device.getName().equals("U02AF021")){
try {
// 一進來一定要停止搜尋
mBluetoothAdapter.cancelDiscovery();
setTitle("U02AF021"); //証明確有進來此要連結的裝置段落
// 連結到該裝置
mBluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
mBluetoothSocket.connect();
// 取得outputstream
mOutputStream = mBluetoothSocket.getOutputStream();
// 送出訊息
String message = "hello";
mOutputStream.write(message.getBytes());
} catch (IOException e) {
}
}
}
}
};
作者:
whl
時間:
2014-7-17 07:38
如果先用手動方式連接呢?
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1