You know that with Marshmallow you need these permissions for your task -
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Also, starting with Marshmallow , you should programmatically request permissions, even if you declared them in the manifest file.
Therefore, you must request access permissions before you startDiscovery()
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1001);
And after the user accepts these permissions, you can startDiscovery() . And if he / she denies, you cannot detect the device. You can check user action in
onRequestPermissionsResult() callback.
Shadab ansari
source share