BLEClient.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:Quick-Bluetooth-LE 作者:
public BLEClient.BtError checkBluetooth(){
    btManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
    btAdapter = btManager.getAdapter();
    if(!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH))
        return BLEClient.BtError.NoBluetooth;
    if(!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
        return BLEClient.BtError.NoBLE;
    if(btAdapter == null || !btAdapter.isEnabled())
        return BLEClient.BtError.Disabled;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && useNewMethod){
        if((ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) &&
                (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED)){
            return BtError.NoLocationPermission;
        }
        LocationManager lm = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
        if(!(lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) && !(lm.isProviderEnabled(LocationManager.GPS_PROVIDER))){
            return BtError.LocationDisabled;
        }
    }
    return BLEClient.BtError.None;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号