Android bluetooth connection doesn't close after application crash

前端 未结 2 1672
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 06:48

i\'m using SPP profile for connect to my device:

    Set devices = ba.getBondedDevices();
    for(BluetoothDevice bd : devices)
    {
         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 07:03

    I solved this problem by letting my BluetoothSockets be managed by a Service running in its own process. I open, close, read, and write the sockets by passing Messages to and from the Service. If the app crashes, the Service shuts down cleanly, closing the sockets. (It does not shut down cleanly if it's running in the same process as the app.)

提交回复
热议问题