android 蓝牙功能
来源:互联网 发布:mac dock栏随鼠标跳动 编辑:程序博客网 时间:2024/04/29 13:19
public class MainActivity extends Activity{ int REQUEST_ENABLE_BT = 1; …… @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initBluetooth(); } /*判断手机是否已经打开蓝牙,如果没有,询问用户是否要打开*/ @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public void initBluetooth() { //如果手机硬件不支持蓝牙,弹出提示消息 if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { Toast.makeText(this, "Not support BLE", Toast.LENGTH_SHORT).show(); // finish(); } //获取手机本地的蓝牙适配器 final BluetoothManager bluetoothManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE); BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter(); //如果蓝牙没打开,询问用户是否要打开蓝牙 if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } }}
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); //获取已配对的蓝牙设备 Set<BluetoothDevice> devices = adapter.getBondedDevices(); for (BluetoothDevice device : devices) { System.out.println("已配对的设备名称:" + device.getName() + "uuids" + device.getUuids()); }
阅读全文
0 0
- android 蓝牙功能
- Android蓝牙通信功能开发
- Android蓝牙通信功能开发 .
- android 蓝牙搜索功能实现
- Android 应用程序中-设置-蓝牙,隐藏蓝牙功能
- android 蓝牙bluetooth 4.2.2搜索蓝牙功能实现
- Android pad 连接蓝牙打印机Gprinter---实现蓝牙打印功能
- android 打开蓝牙语音拨号功能
- android连接蓝牙打印机实现打印功能
- android 蓝牙4.0广播功能应用
- 基于Android 的蓝牙A2DP 功能的实现
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android上蓝牙通信功能开发:BluetoothChat例程分析
- android 蓝牙设置界面高级选项功能解析
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- 基于Android 的蓝牙A2DP 功能的实现
- Android平台开发-Bluez function porting-蓝牙功能移植
- 如果AI能够测试软件修复bug 程序员会更轻松吗? | 讨论
- virtualenv 基础命令
- hihoCoder#1608 : Jerry的奶酪(dp)
- 网易AI英雄风云榜评选:谁是2017 年AI人物 TOP 10? | 评选
- SpringCloud(第 038 篇)idea环境热部署微服务开发
- android 蓝牙功能
- 使用golang开发selpg命令行程序
- 在杨氏矩阵中找数字,存在返回下标,不存在返回“不存在”,杨氏矩阵:每行每列的数字都是递增排序的
- Leetcode530. Minimum Absolute Difference in BST
- SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
- 【Windows】重叠I/O之事件对象通知
- Android 自定义View---ToggleButton
- 强军征程
- SpringCloud(第 040 篇)链接Mysql数据库,通过CrudRepository编写数据库访问