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:)

  • 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.

  • Thank you Hung Bui,

    Yes I know ANCS is for apple.What does it mean manually?

  • It means there is no support on the Android phone. You need to write your own code to detect notification, for example a phone call. And then you send the notification (by your app on the phone) to the nRF5 device. As what iOS does for you when you use ANCS. You can either choose to do it exactly the same way as Apple defined with iOS or you can choose to do it your own way of notifying.

  • 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?

  • I'm not so sure it has to do a write request. As far as I know it just need to enable notification on the ANCS server on the phone. So it can receive notification packet from the phone to the device. What you need to implement on the Android phone is similar to the test with nRFConnect described here.

Related