up

On Wednesday, August 17, 2016 at 11:36:57 AM UTC-3, Gustavo Monteiro wrote:
>
> Hello,
>
> I'm working on a project in android that uses Bluetooth low energy (BLE). 
> I have a DeviceScanFragment that shows a list of all BLE devices. When I 
> select a device to connect, it should go to another fragment (
> ScanProfessionalFingerprintFragment ), start the BluetoothLeService and 
> connect.
>
> The problem is that sometimes it doesn't connect. The BluetoothGattCallback 
> on the BluetoothLeService receives status 133.
>
> private final BluetoothGattCallback mGattCallback = new 
> BluetoothGattCallback() {
>     @Override
>     public void onConnectionStateChange(BluetoothGatt gatt, int status, int 
> newState) {
>         String intentAction;
>
>         if (newState == BluetoothProfile.STATE_CONNECTED) {
>             intentAction = ACTION_GATT_CONNECTED;
>             mConnectionState = STATE_CONNECTED;
>             broadcastUpdate(intentAction);
>             Log.i(TAG, "Connected to GATT server.");
>             // Attempts to discover services after successful connection.
>             Log.i(TAG, "Attempting to start service discovery:" +
>                     mBluetoothGatt.discoverServices());
>
>         } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
>             intentAction = ACTION_GATT_DISCONNECTED;
>             mConnectionState = STATE_DISCONNECTED;
>             Log.i(TAG, "Disconnected from GATT server.");
>             broadcastUpdate(intentAction);
>         }
>     }
>
>
> After that I receive ACTION_GATT_DISCONNECTED in the BroadcastReceiver on 
> the ScanProfessionalFingerprintFragment  and it doesn't connects.
>
>
> private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() 
> {
>     @Override
>     public void onReceive(Context context, Intent intent) {
>         final String action = intent.getAction();
>         if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
>             mConnected = true;
>             updateConnectionState(R.string.connected, mConnected);
>             getActivity().invalidateOptionsMenu();
>         } else if 
> (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
>             mConnected = false;
>             updateConnectionState(R.string.disconnected, mConnected);
>             getActivity().invalidateOptionsMenu();
>
>         } else if 
> (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
>             // Show all the supported services and characteristics on the 
> user interface.
>             
> displayGattServices(mBluetoothLeService.getSupportedGattServices());
>             if(mGattCharacteristics != null && mGattCharacteristics.get(0) != 
> null && mGattCharacteristics.get(0).get(0) != null) {
>
>                 mBluetoothLeService.writeCharacteristic( 
> prepareCharacteristic(), Constants.REQUEST_CONNECTION_CODE_1);
>                 mBluetoothLeService.readCharacteristic( 
> prepareCharacteristic());
>
>             }
>         } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
>             displayData( intent.getBooleanExtra("receivedProfessional", 
> false));
>
>         }
>     }
> };
>
>    
> What could it be?
>
> Thanks,
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/c11d42fd-de8b-499f-985c-283ca5ae2436%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to