Android BLE setcharacteristicnotification receive no data

Source: Internet
Author: User

Reference connection: http://www.codes51.com/article/detail_4021799.html

Problem description recently developed on Android BLE read/write Data

However, writing data to the device is smooth, but it is not acceptable to receive data from the device.

/**     * Enables or disables notification on a give characteristic.     *     * @param characteristic characteristic to act on.     * @param enabled        If True, enable notification.  False otherwise.     *    /public void setcharacteristicnotification (bluetoothgattcharacteristic characteristic,                                              Boolean enabled) {        if (Mbluetoothadapter = = NULL | | mbluetoothgatt = = NULL) {            LOG.W (TAG, "Bluetoothadapter not Initialized"); 
   
    return;        }        Mbluetoothgatt.setcharacteristicnotification (characteristic, enabled);        }
   

The above-mentioned is not receiving data, the main is to add less mbluetoothgatt.writedescriptor (descriptor);

The following is the modified code

   /** * Enables or disables notification on a give characteristic.     * * @param characteristic characteristic to act on.  * @param enabled IF True, enable notification.     False otherwise.                                              */public void setcharacteristicnotification (bluetoothgattcharacteristic characteristic, Boolean enabled) {if (Mbluetoothadapter = = NULL | | mbluetoothgatt = = NULL) {LOG.W (TAG,            "Bluetoothadapter not initialized");        Return }//mbluetoothgatt.setcharacteristicnotification (characteristic, enabled);Boolean isenablenotification = mbluetoothgatt.setcharacteristicnotification (characteristic, enabled); if (isenablenotification) {list<bluetoothgattdescriptor> descriptorlist = characteristic.getdescriptors (            );  if (descriptorlist! = null && descriptorlist.size () > 0) {for (Bluetoothgattdescriptor descriptor                    : descriptorlist) {descriptor.setvalue (bluetoothgattdescriptor.enable_notification_value);                Mbluetoothgatt.writedescriptor (descriptor); }            }        }}

If that's not the case, it's another possibility. The characteristic UUID setting is incorrect

You can look at the Boolean isenablenotification = Mbluetoothgatt.setcharacteristicnotification (characteristic, enabled);

Whether the return is false or true,

In addition, we will write an article about the Bluetooth data read and write

The above describes the Android BLE setcharacteristicnotification receive no data, including the content, I hope to be interested in Android development friends helpful.

This article site link: http://www.codes51.com/article/detail_4021799.html

Android BLE setcharacteristicnotification receive no data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.