android监测蓝牙程序是否开启,若要开启记得在xml中添加蓝牙权限
private void checkBluetoothValid() { final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if(adapter == null) { AlertDialog dialog = new AlertDialog.Builder(this).setTitle("错误").setMessage("你的设备不具备蓝牙功能!").create(); dialog.show(); return; } if(!adapter.isEnabled()) { AlertDialog dialog = new AlertDialog.Builder(this).setTitle("提示") .setMessage("蓝牙设备未打开,请开启此功能后重试!") .setPositiveButton("确认", new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { Intent mIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(mIntent, 1); } }) .create(); dialog.show(); } }