綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] 用Ken Yang 筆記: Android Bluetooth API範例去連結到裝置沒反應

[複製連結] 查看: 1817|回覆: 1|好評: 0
跳轉到指定樓層
樓主
softkk | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2014-7-16 15:35

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
程式段如下,驗證確定有進入要連結的裝置"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) {
      
                        }
                }
           
            }
       }
};
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
whl | 收聽TA | 只看該作者
發表於 2014-7-17 07:38
如果先用手動方式連接呢?
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則