Trying to connect to iOS via BLE + BT through Android device

83 views Asked by At

I am trying to connect to the i-phone via Android Bluetooth + BLE. My goal is to read iOS notifications via Android Bluetooth + BLE.

I am able to show the i-phone Bluetooth in the android app and was able to connect to the i-phone but I am unable to found the Notification characteristic.

I got notification characteristic UUID from this link I am using Notification Source: UUID

Here is my BluetoothGattCallback:

public BluetoothGattCallback mCallback = new BluetoothGattCallback() {
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
            super.onConnectionStateChange(gatt, status, newState);

            if (status == BluetoothGatt.GATT_SUCCESS) {
                if (newState == BluetoothProfile.STATE_CONNECTED) {
                    final BluetoothGatt mGatt = gatt;
                    Handler handler;
                    handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            mGatt.discoverServices();
                        }
                    });
                    //gatt.discoverServices();

                } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                    try
                    {
                        Log.i("no_conn", "Connection unsuccessful with status"+status);
                        //mGatt.disconnect();
                        mGatt.close();
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        }

        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            super.onServicesDiscovered(gatt, status);

            if (status != BluetoothGatt.GATT_SUCCESS) {
                Log.i("Not success", "Device service discovery unsuccessful, status " + status);
                return;
            }
            List<BluetoothGattService> matchingServices = gatt.getServices();
            gatt.getService(UUID.fromString(SERVICE_STRING));
            List<BluetoothGattCharacteristic> matchingCharacteristics = BluetoothUtils.findCharacteristics(gatt);
            if (matchingCharacteristics.isEmpty()) {
                Log.i("No characteristics", "Unable to find characteristics.");
                showToast("No characteristic found");
                return;
            }else {
                showToast("characteristic found");
            }
        }
    }; 

Here is my findCharacteristics function:

public static List<BluetoothGattCharacteristic> findCharacteristics1(BluetoothGatt bluetoothGatt) {
        List<BluetoothGattCharacteristic> matchingCharacteristics = new ArrayList<>();

        List<BluetoothGattService> serviceList = bluetoothGatt.getServices();
        BluetoothGattService service = null;
        
        for (BluetoothGattService bgservice : serviceList) {
            String serviceIdString = bgservice.getUuid()
                    .toString();
            if (matchesServiceUuidString(serviceIdString)) {
                service = bgservice;
            }
        }
        
        if (service == null) {
            Log.i("Null service", "Null service.");
            return matchingCharacteristics;
        }
        return matchingCharacteristics;
    }

Here I am matching with serviceIdString with the Notification Source: UUID. Am I missing anything?

0

There are 0 answers