1
votes

I am trying to write an android app which is a chat app via BLE.

<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>

I got that message in log cat and not trigger onLeScan() method while scanning device.

D/BluetoothAdapter: startLeScan(): null

D/BluetoothAdapter:onClientRegistered() - status=0 clientIf=5

D/BluetoothAdapter: stopLeScan()

My code for scanning device is

private BluetoothAdapter.LeScanCallback mLeScanCallback =
            new BluetoothAdapter.LeScanCallback() {

                @Override
                public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, device.getName(), Toast.LENGTH_SHORT)
                                    .show();
                        }
                    });
                }
            };

private void scanLeDevice(final boolean enable) {
        if (enable) {
            // Stops scanning after a pre-defined scan period.
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mScanning = false;
                    mBluetoothAdapter.stopLeScan(mLeScanCallback);
                    invalidateOptionsMenu();
                }
            }, SCAN_PERIOD);

            mScanning = true;
            mBluetoothAdapter.startLeScan(mLeScanCallback);
        } else {
            mScanning = false;
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
    }

when I check my devices specification, they support only buletooth smart, not peripheral mode. My question is that Is it possible to connect BLE supported moblie phone each other without peripheral mode supported? Or is my code just something wrong ?

Edit

I have 3 test devices which are Huawei 730 with android 4.3, Samsung galaxy core 2 with android 4.4.2 and Android one with android 6.0.1. My problem occurred to all of them. I also test with BLEScanner but not detect all my devices. Additionally, I can't detect all my device by running BluetoothLeGatt which is sample project from android sdk.

1
Can you provide more details?: Android version, Phone model, etc...Roberto Betancourt
@dustedrob I've updated my question.Arkar Aung

1 Answers

1
votes

I've found the answer. This is because there is no support for peripheral mode in pre-lollipop device. One of your phone which acts as peripheral device must have android version 5.0 (Lollipop) and above so that it can advertise its presence, create GATTServer and let another phone to connect it as central/client.

Make communication between 2 android phones over BLE

https://developer.android.com/about/versions/android-5.0.html#BluetoothBroadcasting

Edit

Even some of lollipop and above phones do not support peripheral mode due to hardware requirement.

Hope it will be useful for you.