<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hello"
/>
<Button
android:id="@+id/scanButtonId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="扫描周围的蓝牙设备"
/>
</LinearLayout>
private class ButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
//得到BluetoothAdapter对象
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
//判断BluetoothAdapter对象是否为空,如果为空,则没有蓝牙设备
if (adapter != null) {
System.out.println("本机拥有蓝牙设备");
if (!adapter.isEnabled()) {
//如果蓝牙不可用,启动蓝牙
System.out.println("提示启动蓝牙");
Intent intent = new Intent(
BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
}
//得到所有已经配对的蓝牙适配器对象(没有打开蓝牙不能搜索到已经匹配的设备)
Set<BluetoothDevice> devices = adapter.getBondedDevices();
if (devices.size() > ) {
for (Iterator iterator = devices.iterator(); iterator
.hasNext();) {
BluetoothDevice bluetoothDevice = (BluetoothDevice) iterator
.next();
//得到远程蓝牙设备的地址
System.out.println(bluetoothDevice.getAddress());
}
}
} else {
System.out.println("不存在蓝牙设备");
}
}
}
<uses-permission android:name="android.permission.BLUETOOTH"/>

android之蓝牙设备的使用01的更多相关文章

  1. Android 扫描蓝牙设备

    Android扫描蓝牙设备是个异步的过程,核心的步骤为:调用bluetoothAdapter的startDiscovery()进行设备扫描,扫描的结果通过广播接收处理!具体如下: 1.申请相关权限 & ...

  2. 【起航计划 002】2015 起航计划 Android APIDemo的魔鬼步伐 01

    本文链接:[起航计划 002]2015 起航计划 Android APIDemo的魔鬼步伐 01 参考链接:http://blog.csdn.net/column/details/mapdigitap ...

  3. Android 读取蓝牙设备信息开发

    (1)Android手机一般以客户端的角色主动连接SPP协议设备(接上蓝牙模块的数字传感器),连接流程是: 1.使用registerReceiver注册BroadcastReceiver来获取蓝牙状态 ...

  4. 蓝牙UUID——Android各种蓝牙设备的UUID

    本文转自:http://www.14blog.com/archives/481 UUID是“Universally Unique Identifier”的简称,通用唯一识别码的意思.对于蓝牙设备,每个 ...

  5. Android JNI和NDK学习(01)--搭建NDK开发环境(转)

    本文转自:http://www.cnblogs.com/skywang12345/archive/2013/05/23/3095013.html 本文主要介绍“JNI”.“Android NDK”以及 ...

  6. Android各种蓝牙设备的UUID(转)

    转自:http://www.14blog.com/archives/481 UUID是“Universally Unique Identifier”的简称,通用唯一识别码的意思.对于蓝牙设备,每个服务 ...

  7. 【Android 复习】:第01期:引导界面(一)ViewPager介绍和使用详解

    一.ViewPager实现的效果图 二.ViewPager实现的功能 看到上面的效果图,想必大家已经猜出了这个类是干吗用的了,ViewPager类提供了多界面切换的新效果, 新效果有如下特征: < ...

  8. Android 高级UI设计笔记01:使用ExpandableListView组件(ListView的扩展)

    1.ExpandableListView是一个用来显示二级节点的ListView. 比如如下效果的界面: 2.使用ExpandableListView步骤 (1)要给ExpandableListVie ...

  9. Android开发高手课笔记 - 01 崩溃优化(上):关于“崩溃”那点事

    Android 的两种崩溃 Java 崩溃就是在 Java 代码中,出现了未捕获的异常,导致程序异常退出 Native 崩溃一般都是因为在 Native 代码中访问非法地址,也可能是地址对齐出了问题, ...

随机推荐

  1. 论文笔记之:Multiple Object Recognition With Visual Attention

     Multiple Object Recognition With Visual Attention Google DeepMind  ICRL 2015 本文提出了一种基于 attention 的用 ...

  2. 上传按钮样式优化 <input type="file" />

    <html><head><title>上传按钮样式优化</title> <style>.form-element-file-wapper { ...

  3. 设置EDIUS字幕时有哪些要注意的

    我们在用EDIUS添加字幕,有时候可能会遇到以下麻烦.例如有的字体在EDIUS中找不到,诗歌的排版问题还有怎么给字幕加光效等等.今天小编主要来给大家解决这三个问题,让你们知道EDIUS字幕设置时应该注 ...

  4. Python_Day6_反射_正则表达式之篇

    一.反射 定义:利用字符串形式去对象(模块)中操作(寻找/检查/删除/设置)成员 #getattr:获取模块中属性 #hasattr:检查模块中是否存在某个成员(函数) #delattr:删除模块中成 ...

  5. libc-glibc

    glibc 和 libc 都是 Linux 下的 C 函数库. libc 是 Linux 下的 ANSI C 函数库:glibc 是 Linux 下的 GUN C 函数库. ANSI C 和 GNU ...

  6. html之dl标签

    用来定义列表之用 通常与dt:定义列表中的项目 dd:描述列表中的项目 示例代码: <dl> <dt>数据库</dt> <dd>oracle</d ...

  7. IOS:被误解的MVC和被神化的MVVM

    MVC的历史 MVC,全称是 Model View Controller,是模型 (model)-视图 (view)-控制器 (controller) 的缩写.它表示的是一种常见的客户端软件开发框架. ...

  8. tnsnames linux找的位置顺序

    In Sue’s article, it states that SQLDeveloper looks for a tnsnames.ora in the following places in th ...

  9. 转:vs发布window应用程序时出错:未能签名 ...\setup.exe

      在vs发布window应用程序过程中,提示“SignTool 报告了一个错误‘未能签名 ...\setup.exe.SignTool 错误: ISignCode::Sign 返回的错误: 0x80 ...

  10. collection的框架结构

    经常会看到程序中使用了记录集,常用的有Collection.HashMap.HashSet.ArrayList,因为分不清楚它们之间的关系,所以在使用时经常会混淆,以至于不知道从何下手.在这儿作了一个 ...