与Android 6.0盯着它是不足以包含清单的权限。 您必须明确询问用户每个被认为“危险”的权限。 BluetoothDevice.ACTION_FOUND需要蓝牙以及ACCESS_COARSE_LOCATION权限 http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#ACTION_FOUND
的ACCESS_COARSE_LOCATION http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION 是一个“危险”的许可,因此,你要问使用做实际的发现之前它requestPermission了。
public void doDiscovery() {
int hasPermission = ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION);
if (hasPermission == PackageManager.PERMISSION_GRANTED) {
continueDoDiscovery();
return;
}
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{
android.Manifest.permission.ACCESS_COARSE_LOCATION},
REQUEST_COARSE_LOCATION_PERMISSIONS);
}
然后你会得到用户的答案上onRequestPermissionsResult
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case REQUEST_COARSE_LOCATION_PERMISSIONS: {
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
continueDoDiscovery();
} else {
Toast.makeText(this,
getResources().getString(R.string.permission_failure),
Toast.LENGTH_LONG).show();
cancelOperation();
}
return;
}
}
}
要使用的机器人,你应该使用兼容库,并使用ActivityCompat
哪些设备遇到此问题?哪个连结?我使用Nexus 5 –
这是一个联系5 – eldina