Android 监测蓝牙程序是否开启
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();
}
}
欢迎关注技术公众号,微信号搜索ColorfulCode 代码男人
分享技术文章,投稿分享,不限技术种类,不限技术深度,让更多人因为分享而受益。