Runtime permissions

In addition to the manifest permissions, Android needs explicit runtime permissions for Bluetooth and Coarse Location. Irrespective of the application flow, these permissions should be asked at the start of the application lifetime. To get the coarse location permission, you can add:

if (this.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {     requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_CODE_COARSE_PERMISSION); }

The method checkSelfPermission confirms if the location permission is not already given. On the other hand, the REQUEST_CODE_COARSE_PERMISSIONis a static integer which can be caught by overriding onRequestPermissionResult() ...

Get Building Bluetooth Low Energy Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.