Giter Site home page Giter Site logo

lmbluetoothsdk's People

Contributors

reymundolopez avatar shahimclt avatar ulizama avatar whilu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lmbluetoothsdk's Issues

Maintaining Connection Between Activities

Hi could you suggest the ideal way to maintain connection between activities.

I am defining the BluetoothController as static in main activity and defining a local as follows
public BluetoothController mBluetoothController = MainActivity.mBluetoothController;

and then using that object i read the incoming data

mBluetoothController.setBluetoothListener(new BluetoothListener() { ... }

This works 90% of the time but i get this error at times
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.x/com.x.yActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void co.lujun.lmbluetoothsdk.BluetoothController.setBluetoothListener(co.lujun.lmbluetoothsdk.base.BluetoothListener)' on a null object reference

Do let me know how i can resolve this issue !!

Bluetooth call back not working in the foreground service on Android 10

Recently i have implemented the Bluetooth scanning in the foreground service every 5minutes.

I have noticed that in android 10 Samsung a11 device scan results are empty during screen lock and if its in background.

Also i had quick look on your code to fix this issue but everything seems good in the BLEController.java class you have added scan settings based on different android device.

But still i cant fix it? any guess or fix you may know?

接收器读取bug

try {
if (mmInStream.read()<=0){
continue;
}else {
Thread.sleep(1000);
}
bytes = mmInStream.read(buffer);
if (bytes > 0) {
byte[] data = Arrays.copyOf(buffer, bytes);
if (mBluetoothListener != null) {
((BluetoothListener) mBluetoothListener).onReadData(mmSocket.getRemoteDevice(), data);
}
}

STATE_LISTEN

I do not use startAsServer() method but sometimes I got STATE_LISTEN after STATE_CONNECTING in onBluetoothServiceStateChanged. In that case, I cannot connect to my target device (microcontroller). disconnect() and reconnect() does not help. What should I do? Is it a bug?

BLE scan

Please add callback on finish/stop scanning BLE devices,
Please add check if scanning now.
Thanks for your support.

Characteristic Notification

Hi,
I try to set characteristic notification with:
BluetoothLEController.getInstance().setReadCharacteristic(MY_CHARACTERISTIC_UUID_AS_STRING);
But that doesn't work, onDataChanged(BluetoothCharacteristic characteristic) is not called.
Following the Bluetooth Smart standard on Android, you also need to write to the descriptor which is not done in the library.
I've downloaded the library from Github and did the following modification:
for (BluetoothGattDescriptor descriptor : descriptors) { if (descriptor.getUuid().equals(Descriptor.CLIENT_CHARACTERISTIC_CONFIGURATION)) { BluetoothLEController.getInstance().setReadCharacteristic(MY_CHARACTERISTIC_UUID_AS_STRING); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } }
And then I become the notifications. Either you should change this directly in the library or you could send back mBluetoothGatt in onDiscoveringCharacteristics so we can write to the descriptor ourselves.
Let me know what you think about it.
Best,
JB

Message duplication

Hello!

I faced with some issue.
I'm trying to send a number of messages through BT using this lib. My code looks like

for (Banner bannerItem : banners) {
                JSONObject bannerJson = new JSONObject();
                bannerJson.put("image",bannerItem.getImageUrl());
                bannerJson.put("position", bannerItem.getPosition());
                ALog.error("Do Send %s", bannerJson.toString());
                bluetoothController.write(bannerJson.toString().getBytes());
 }

Sometimes receiver app receives current item and previous one, e.g.
first message: {banner ob 1}
second message: {banner ob 1}{banner obj 2}

Bug with receiver

    @Override
    protected void onCreate(){
              mBLEController = BluetoothLEController.getInstance().build(this);
              mBLEController.setBluetoothListener(bluetoothLEListener);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        try {
            mBLEController.release();
        }catch (Exception e){
            LogManager.LogEA(e);
        }
    }

     @Override
    protected void onPause() {
        super.onPause();
       /*my custom key, use when scanLe*/
        if(getCurrentState() == START_SCAN_STATE) {
            mBLEController.cancelScan();
        }
    }

image

Please fix, thank you for support.
I am using BLE Simulator (Battery Service).

BLE callback on init

Please add callback when BLEService was inited, thanks. Sorry, but I use fragment and main activity is owner BLE Service, so I needed callback on service connection at fragment

    private final ServiceConnection serviceConnectionListener = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            LogManager.LogEA("Service connected");
            mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
            if (!mBluetoothLeService.initialize()) {
                LogManager.LogEA(getString(R.string.unable_to_initialize_bluetooth));
                MainActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setMessage(getString(R.string.unable_to_initialize_bluetooth)).setCancelable(false);
                        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                MainActivity.this.finish();
                            }
                        });
                        builder.create().show();
                    }
                });
            }else{
                bluetoothListener.onBluetoothServiceConnected();
                LogManager.LogEA(bluetoothListener.getBluetoothListenerId());
            }

        @Override
        public void onServiceDisconnected(ComponentName componentName) {
            mBluetoothLeService = null;
            LogManager.LogEA("Service disconnected");
        }
    };

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.