前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android 监测蓝牙程序是否开启

Android 监测蓝牙程序是否开启

作者头像
黄林晴
发布2019-01-10 15:55:40
1.4K0
发布2019-01-10 15:55:40
举报
文章被收录于专栏:代码男人代码男人代码男人

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(); } }

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年09月13日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档