This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to receive nRF51 BLE device from android phone notifications?

Hi I'm creating an android app for smartwatch(used nrf51 ble),I have two questions

1.I used ANCS(Apple notification center service) in my android app,but nrf51 device didn't read anything.I added ANCS UUID,characteristics and descriptors,but nrf51 didn't fire onCharacteristicReadRequest metho.How can I solve this problem?

2.If I can't use ANCS for android app,what can I use to receive all android phone notiifcations?

Thanks:)

Parents
  • Hi Enes,

    ANCS is for apple. Android doesn't support it natively. You need to write your code on Android app to send notifications manually. This is the same as defining your own service and characteristic (with ble_app_uart for example).

    Re-using ANCS on Android has the benefit that you don't need different firmware on the nRF52 size to deal with Android vs iOS.

  • OK I did ANCS way but nrf51 didn't write or read request on my notification data source.This is my codes

    @Override
        public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
            super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
            Log.i(TAG, "onCharacteristicWriteRequest, Device: " + device.getName() + " Characteristic:" + characteristic.getUuid());
    
            StringBuilder byteArray = new StringBuilder();
            for (byte b: value){
                byteArray.append(String.format("%20x ", b));
            }
         
    
            byte[] content = {0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x02, 0x00, 0x4d, 0x00, 0x65, 0x03, 0x00, 0x48, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f};
            mGattServer.sendResponse(device, requestId, 0, 0, content);
            charDataSource.setValue(content);
        }
    

    I think content is wrong?

Reply
  • OK I did ANCS way but nrf51 didn't write or read request on my notification data source.This is my codes

    @Override
        public void onCharacteristicWriteRequest(BluetoothDevice device, int requestId, BluetoothGattCharacteristic characteristic, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
            super.onCharacteristicWriteRequest(device, requestId, characteristic, preparedWrite, responseNeeded, offset, value);
            Log.i(TAG, "onCharacteristicWriteRequest, Device: " + device.getName() + " Characteristic:" + characteristic.getUuid());
    
            StringBuilder byteArray = new StringBuilder();
            for (byte b: value){
                byteArray.append(String.format("%20x ", b));
            }
         
    
            byte[] content = {0x00, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x02, 0x00, 0x4d, 0x00, 0x65, 0x03, 0x00, 0x48, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x6f};
            mGattServer.sendResponse(device, requestId, 0, 0, content);
            charDataSource.setValue(content);
        }
    

    I think content is wrong?

Children
No Data
Related