android - How to connect paired device via Bluetooth for TV(REMOTE)? -
my code
mbluetoothadapter = bluetoothadapter.getdefaultadapter(); if (mbluetoothadapter != null) { // device not support bluetooth if (!mbluetoothadapter.isenabled()) { intent enablebtintent = new intent(bluetoothadapter.action_request_enable); startactivityforresult(enablebtintent, 10); }else{ set<bluetoothdevice> paireddevices = mbluetoothadapter.getbondeddevices(); // if there paired devices if (paireddevices.size() > 0) { // loop through paired devices (final bluetoothdevice device : paireddevices) { // add name , address array adapter show in listview //marrayadapter.add(device.getname() + "\n" + device.getaddress()); devname = device.getname(); devadd = device.getaddress(); if(!devname.isempty()) { txtdesc.settext(devname); progressbar.setvisibility(view.gone); } txtdesc.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //intent cameraintent = new intent(android.provider.mediastore.action_image_capture); //startactivityforresult(cameraintent, 2); new connectthread(device); } }); } }
for call connectedthread
private class connectthread extends thread { private bluetoothsocket mmsocket; public final bluetoothdevice mmdevice; public connectthread(bluetoothdevice device) { // use temporary object later assigned mmsocket, // because mmsocket final bluetoothsocket tmp = null; mmdevice = device; // bluetoothsocket connect given bluetoothdevice try { uuid my_uuid = mmdevice.getuuids()[0].getuuid(); // my_uuid app's uuid string, used server code tmp = device.createinsecurerfcommsockettoservicerecord(my_uuid); mmsocket = tmp; mbluetoothadapter.canceldiscovery(); if(!mmsocket.isconnected()){ log.e("tag" , "connection started."); mmsocket.connect(); log.e("tag", "connection ended."); } } catch (ioexception e) { log.e("exc" ,""+ e.getmessage()); toast.maketext(getapplicationcontext() , "unable connect." , toast.length_long).show(); try { mmsocket.close(); } catch (ioexception closeexception) { } return; } }
so used block of code , got paired device , when click on particular device going connect showing :
e/tag: connection started. 09-10 17:04:29.770 9565-9565/ir.abc.com.irremote d/bluetoothutils: issocketallowedbysecuritypolicy start : device null 09-10 17:04:29.770 9565-9565/ir.abc.com.irremote d/bluetoothsocket: connect(): myuserid = 0 09-10 17:04:29.770 9565-9565/ir.abc.com.irremote w/bluetoothadapter: getbluetoothservice() called no bluetoothmanagercallback 09-10 17:04:29.780 9565-9565/ir.abc.com.irremote d/bluetoothsocket: connect(), socketstate: init, mpfd: {parcelfiledescriptor: filedescriptor[40]} 09-10 17:04:36.205 9565-9565/ir.abc.com.irremote e/exc: read failed, socket might closed or timeout, read ret: -1 09-10 17:04:36.245 9565-9565/ir.abc.com.irremote d/bluetoothsocket: close() in, this: android.bluetooth.bluetoothsocket@bb242a6, channel: -1, state: init 09-10 17:04:36.245 9565-9565/ir.dumadu.com.irremote d/bluetoothsocket: close() this: android.bluetooth.bluetoothsocket@bb242a6, channel: -1, msocketis: android.net.localsocketimpl$socketinputstream@3d9924e7, msocketos: android.net.localsocketimpl$socketoutputstream@151d4894msocket: android.net.localsocket@200d2f3d impl:android.net.localsocketimpl@302fe332 fd:filedescriptor[40] 09-10 17:04:36.245 9565-9565/ir.abc.com.irremote d/bluetoothsocket: closing msocket: android.net.localsocket@200d2f3d impl:android.net.localsocketimpl@302fe332 fd:filedescriptor[40] 09-10 17:04:36.245 9565-9565/ir.abc.com.irremote i/choreographer: skipped 389 frames! application may doing work on main thread. 09-10 17:04:36.250 9565-9565/ir.abc.com.irremote d/viewrootimpl: buffer count app info ::-1 && -1 :: ir.abc.com.irremote view :: -1 dbq enabled ::false false 09-10 17:04:36.280 9565-9600/ir.abc.com.irremote d/mali_winsys: new_window_surface returns 0x3000, [265x78]-format:1 09-10 17:14:40.345 9565-9565/ir.dumadu.com.irremote v/activitythread: updatevisibility : activityrecord{fd05a00 token=android.os.binderproxy@2ba635fc {ir.abc.com.irremote/ir.abc.com.irremote.ir.abc.com.irremote.activity.wificonnection}} show : true
Comments
Post a Comment