Enable bluetooth tethering android programmatically -


i trying make application "bluetooth auto tethering" on play store. read on forum android security-aware , not enable setting without user interaction.

i need explanations how enable bluetooth tethering.

thank you

i don't know if still issue or not, found using connect method in reflection call works. working off of code pmont used link in lorelorelore's answer:

bluetoothadapter mbluetoothadapter = bluetoothadapter.getdefaultadapter(); class<?> classbluetoothpan = null; constructor<?> btpanctor = null; object btsrvinstance = null; method mbtpanconnect;  try {     classbluetoothpan = class.forname("android.bluetooth.bluetoothpan");     mbtpanconnect = classbluetoothpan.getdeclaredmethod("connect", bluetoothdevice.class);     btpanctor = classbluetoothpan.getdeclaredconstructor(context.class, bluetoothprofile.servicelistener.class);     btpanctor.setaccessible(true);     btsrvinstance = btpanctor.newinstance(mycontext, new btpanservicelistener(mycontext)); } catch (classnotfoundexception e) {     e.printstacktrace(); } catch (exception e) {     e.printstacktrace(); }  set<bluetoothdevice> paireddevices = mbluetoothadapter.getbondeddevices(); // if there paired devices if (paireddevices.size() > 0) {     // loop through paired devices     (bluetoothdevice device : paireddevices) {         try{             mbtpanconnect.invoke(btsrvinstance, device);         }         catch (exception e) {             e.printstacktrace();         }     } } 

of course, assumes bluetooth enabled, , have 1 paired device. enabling bluetooth pretty straightforward using standard (not reflection) calls, , can check paired device want connect in for loop. also, don't forget btpanservicelistener class other answer well.

hope helps.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -