android - How to turn on bluetooth on button click -
in application, need turn on bluetooth of device on button click. how can achieve that? example helpful. also, permissions require include in mainfest.xml same?
following code excerpts android documentation on bluetooth
in manifest file permissions:
<manifest ... > <uses-permission android:name="android.permission.bluetooth" /> ... </manifest>
source code enable bluetooth
bluetoothadapter mbluetoothadapter = bluetoothadapter.getdefaultadapter(); if (mbluetoothadapter == null) { // device not support bluetooth } if (!mbluetoothadapter.isenabled()) { intent enablebtintent = new intent(bluetoothadapter.action_request_enable); startactivityforresult(enablebtintent, request_enable_bt); }
if enabling bluetooth succeeds, activity
receive result_ok
result code in onactivityresult()
callback. if bluetooth not enabled due error (or user responded "no") result code result_canceled
.
Comments
Post a Comment