Skip to content Skip to sidebar Skip to footer

Bluetooth Le Gatt Not Finding Any Devices

ANSWER: Special thanks to Nelson Hoang below for steering me in the right direction and providing valuble resources. Once the code for adding permissions for locations was added (

Solution 1:

Do you have location turned on? Android 6.0+ devices need location to be turned on in order to scan for Bluetooth LE peripherals. Bluetooth Low Energy startScan on Android 6.0 does not find devices

Solution 2:

As per Nelson Hoang's solution above (https://stackoverflow.com/a/37423244/2585501), these were the modifications that were required to be made to BluetoothLeGatt to get BLE working on Android 6.0+ devices;

  1. Manually turn on location services on the Android device

  2. Edit BluetoothLeGatt source (android-BluetoothLeGatt-master.zip):

a) In Application - manifests - AndroidManifest.xml,

Add the following line directly above <uses-permission android:name="android.permission.BLUETOOTH"/>;

<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION" />

b) In Application - java - com.example.android.bluetoothlegatt - DeviceScanActivity.java,

i) Add the following code to the import statements;

import android.Manifest;
import android.os.Build;
import android.util.Log;

ii) Add the following code to public class DeviceScanActivity extends ListActivity;

privatestaticintPERMISSION_REQUEST_CODE=1;
privatefinalstaticStringTAG= DeviceScanActivity.class.getSimpleName();

@OverridepublicvoidonRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults)
{
    if(requestCode == PERMISSION_REQUEST_CODE)
    {
        //Do something based on grantResultsif(grantResults[0] == PackageManager.PERMISSION_GRANTED)
        {
            Log.d(TAG, "coarse location permission granted");
        }
        else
        {
            Log.d(TAG, "coarse location permission denied");
        }
    }
}

ii) Edit the onCreate function (request location permissions);

@OverridepublicvoidonCreate(Bundle savedInstanceState) 
{
    Log.d(TAG, "Request Location Permissions:");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    {
        requestPermissions(newString[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_CODE);
    }
    ...

Post a Comment for "Bluetooth Le Gatt Not Finding Any Devices"