Android: Set Bluetooth Discoverability Unbounded

前端 未结 6 1637
悲&欢浪女
悲&欢浪女 2021-01-06 23:57

I have spent the last couple of days trying to make an app that keeps my Samsung Galaxy S3 mini (Android 2.1.4) discoverable for an \"infinite\" amount of time. My code look

6条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-07 00:12

    Im not sure if this would suit your application or if theres some other reason why you don't want to do this but why not just discover for the default time then restart discovery when it times out? this way it will technically be an unlimited discovery, which will only trigger a VERY slight pause in between, I used this method in my application using a broadcast receiver.

    I put startDiscovery() in the onStart() method to trigger discovery on activity start, then listen to ACTION_DISCOVERY_FINISHED in your broadcast receiver's onReceive() method, here place another call to startDiscovery().

    this will loop the discovery forever, if you want to stop when you find a device then call cancelDiscovery() in you receiver's ACTION_FOUND listener, you can also place some checking here if you need to find a particular device - again in my case i was checking for a particular device's mac address so the discovery would continue until this was found.

    not sure if this is any use but if you need more detail let me know.

提交回复
热议问题