1.android6.0版本搜索蓝牙需要开启位置信息
需在Manifest中添加权限:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
2.添加请求开启位置信息代码
private void mayRequestLocation() { if (Build.VERSION.SDK_INT >= 23) { int checkCallPhonePermission = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION); if(checkCallPhonePermission != PackageManager.PERMISSION_GRANTED){ //判断是否需要 向用户解释,为什么要申请该权限 if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_COARSE_LOCATION)) Toast.makeText(getApplicationContext(),"6.0就是这样坑", Toast.LENGTH_LONG).show(); ActivityCompat.requestPermissions(this ,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},REQUEST_FINE_LOCATION); return; }else{ } } else { } }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
switch (requestCode) {
case REQUEST_FINE_LOCATION:
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else{
// The user disallowed the requested permission.
}
break;
}
}
3.亲测在6.0版本下可以搜索到蓝牙。
4.注:扫描时需关闭WIFI!
原文:http://www.cnblogs.com/boye666/p/6357385.html