when connect ble device android phone in kitkat it's working fine. in case of lollipop or android 5.0 scanning work's , device connected. after 5-10 seconds it's automatically disconnected. why happening don't understand. please me , reply me possible. code is,
bluetoothlescanner = mbluetoothadapter.getbluetoothlescanner(); scancallback mscancallback=new scancallback() { @override public void onscanresult(int callbacktype, scanresult result) { log.i("callbacktype", string.valueof(callbacktype)); log.i("result", result.tostring()); bluetoothdevice btdevice = result.getdevice(); adddevice(btdevice); } }; connect code that
public boolean connect(bluetoothdevice device) { // if (mbluetoothadapter == null || address == null) { // log.w(tag, // "bluetoothadapter not initialized or unspecified address."); // system.out.println("devices mbluetoothadapter && address null "); // return false; // } // // final bluetoothdevice device = // mbluetoothadapter.getremotedevice(address); if (device == null) { log.w(tag, "device not found. unable connect."); // system.out.println("devices devices null "); return false; } // want directly connect device, setting // autoconnect // parameter false. mbluetoothgatt = device.connectgatt(this, false, mgattcallback); log.d(tag, "trying create new connection."); // system.out.println("devices trying create new connection."); mbluetoothdeviceaddress = device.getname(); mconnectionstate = state_connecting; try { thread.sleep(20); } catch (interruptedexception e) { e.printstacktrace(); } return true; }
Comments
Post a Comment