bluetooth – BLE clear cache android studio-ThrowExceptions

Exception or error:

I have a ble connecting app, which works fine only when pressing the BT button off and on from the device itself. tried disconnecting, closing BTGattCharacteristic with no success of dealing with that.
I saw this post:
How to programmatically force bluetooth low energy service discovery on Android without using cache
tried it but nothing happens, something changed and I don’t know how to refresh the BTGatt from code. This is my connect method:

    public boolean connect() {
        BTdevice = mBTAdapter.getRemoteDevice(devcAddress);
        mBTGatt = BTdevice.connectGatt(mContext, false, mGattCallback);
        if (mBTGatt == null){
            Log.d("ADebugTag", "mBTGatt is null");
            return false;
        else {
            try {
                mGattChar = mBTGatt.getService(ServiceUUID).getCharacteristic(CharUUID);
            catch (NullPointerException e){
                Log.d("ADebugTag", "mGattChar is null\n" + e);
            //setCharacteristicNotification(mGattChar, true);
            return true;


How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *