Bluetooth Le Gatt Not Finding Any Devices
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;
Manually turn on location services on the Android device
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-permission android: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
;
private static int PERMISSION_REQUEST_CODE = 1;
private final static String TAG = DeviceScanActivity.class.getSimpleName();
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults)
{
if(requestCode == PERMISSION_REQUEST_CODE)
{
//Do something based on grantResults
if(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);
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.d(TAG, "Request Location Permissions:");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_CODE);
}
...
Post a Comment for "Bluetooth Le Gatt Not Finding Any Devices"