android蓝牙坑,android开发中遇到的坑系列之蓝牙相关

蓝牙连接 其实是socket连接必须在子线程调用 .将connect()方法放在子线程即可.

开发时,在做demo想调通过后在放入子线程,结果卡了好久.切记切记啊

String SPP_UUID = UUID uuid = UUID.(SPP_UUID){

= .createRfcommSocketToServiceRecord(uuid).connect()} (IOException e) {

e.printStackTrace(){

.close()= } (IOException e1) {

e1.printStackTrace()}

-}

09-06 13:44:57.247  27860-27860/com.example.gauravdubey.myapplication I/BT﹕ Attempting to connect to Protocol: 00001101-0000-1000-8000-00805f9b34fb

09-06 13:44:57.247  27860-27860/com.example.gauravdubey.myapplication W/BluetoothAdapter﹕ getBluetoothService() called with no BluetoothManagerCallback

09-06 13:44:57.247  27860-27860/com.example.gauravdubey.myapplication D/BluetoothSocket﹕ connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[56]}

09-06 13:44:58.667  27860-27860/com.example.gauravdubey.myapplication W/BluetoothAdapter﹕ getBluetoothService() called with no BluetoothManagerCallback

09-06 13:44:58.667  27860-27860/com.example.gauravdubey.myapplication D/BluetoothSocket﹕ connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[59]}

09-06 13:45:03.267  27860-27860/com.example.gauravdubey.myapplication W/BT﹕ Fallback failed. Cancelling.

java.io.IOException: read failed, socket might closed or timeout, read ret: -1

at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:505)

at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:482)

at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:324)

at com.example.gauravdubey.myapplication.BluetoothConnector$FallbackBluetoothSocket.connect(BluetoothConnector.java:198)

at com.example.gauravdubey.myapplication.BluetoothConnector.connect(BluetoothConnector.java:62)

at com.example.gauravdubey.myapplication.ConnectThread.run(ConnectThread.java:101)

at com.example.gauravdubey.myapplication.MainActivity$1.onItemClick(MainActivity.java:288)

at android.widget.AdapterView.performItemClick(AdapterView.java:299)

at android.widget.AbsListView.performItemClick(AbsListView.java:1113)

at android.widget.AbsListView$PerformClick.run(AbsListView.java:2911)

at android.widget.AbsListView$3.run(AbsListView.java:3645)

at android.os.Handler.handleCallback(Handler.java:733)

at android.os.Handler.dispatchMessage(Handler.java:95)

at android.os.Looper.loop(Looper.java:136)

at android.app.ActivityThread.main(ActivityThread.java:5001)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:515)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

at dalvik.system.NativeStart.main(Native Method)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值