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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -