蓝牙作为server时 接收不到蓝牙串口模块发送的数据

kinglulu2014 Android基础知识-传感器... 最后由 极客学院-媛儿 于2015年07月06日回复

  • 1 回答
  • 3.5k 浏览
<span style="color:#cc7832;">protected void </span><span style="color:#ffc66d;">listen</span>(){

<span style="color:#cc7832;">try </span>{
<span style="color:#9876aa;">serverSocket </span>= <span style="color:#9876aa;">_bluetooth</span>.listenUsingRfcommWithServiceRecord(<span style="color:#9876aa;font-style:italic;">NAME</span><span style="color:#cc7832;">, </span><span style="color:#9876aa;font-style:italic;">MY_UUID</span>)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#9876aa;">socket </span>= <span style="color:#9876aa;">serverSocket</span>.accept()<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>} <span style="color:#cc7832;">catch </span>(IOException e) {
e.printStackTrace()<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>}
<span style="color:#cc7832;">if</span>(<span style="color:#9876aa;">socket </span>!= <span style="color:#cc7832;">null</span>){
Message msg = <span style="color:#cc7832;">new </span>Message()<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>msg.<span style="color:#9876aa;">obj </span>= <span style="color:#6a8759;">"</span><span style="color:#6a8759;font-family:'宋体';">监听到蓝牙</span><span style="color:#6a8759;">"</span><span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#9876aa;">handler</span>.sendMessage(msg)<span style="color:#cc7832;">;
</span><span style="color:#cc7832;">
</span><span style="color:#cc7832;"> </span>}

Message msg = <span style="color:#cc7832;">new </span>Message()<span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span>msg.<span style="color:#9876aa;">obj </span>= <span style="color:#6a8759;">"</span><span style="color:#6a8759;font-family:'宋体';">进入线程</span><span style="color:#6a8759;">"</span><span style="color:#cc7832;">;
</span><span style="color:#cc7832;"> </span><span style="color:#9876aa;">handler</span>.sendMessage(msg)<span style="color:#cc7832;">;
</span>}

这个是我测试的时候用的 可以进入线程 但是检测时 就看不到字符显示了 不知道哪里有问题

  • 极客学院-媛儿 2015年07月06日 回答 #1楼
  • 代码乱码了,粘入的时候记得要无格式粘贴哦,可以先粘到记事本里再粘到回复框里哦,可以重新提个问题,会有老师为你解答

  • 0 评论