android 蓝牙扫描

来自http://blog.csdn.net/zhangnianxiang/article/details/6655431

扫描周围蓝牙设备的demo

老规矩。右键取得图片地址,利用下载工具下载这个显示不出来的图片。后缀改为rar即可得到源代码项目。


[java]  view plain copy print ?
  1. package zhang.bluetooth;  
  2.   
  3. import java.util.Iterator;  
  4. import java.util.Set;  
  5.   
  6. import android.app.Activity;  
  7. import android.bluetooth.BluetoothAdapter;  
  8. import android.bluetooth.BluetoothDevice;  
  9. import android.content.Intent;  
  10. import android.os.Bundle;  
  11. import android.view.View;  
  12. import android.widget.Button;  
  13.   
  14. public class BlueTooth extends Activity {  
  15.     private Button button;  
  16.     /** Called when the activity is first created. */  
  17.     @Override  
  18.     public void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.main);  
  21.         button=(Button)findViewById(R.id.button);  
  22.         button.setOnClickListener(new Button.OnClickListener(){  
  23.             @Override  
  24.             public void onClick(View arg0) {  
  25.                 // TODO Auto-generated method stub  
  26.                 //得到bluetoothAdapter对象  
  27.                 BluetoothAdapter adapter= BluetoothAdapter.getDefaultAdapter();  
  28.                 //判断BluetoothAdapter师傅哦为空,如果为空,则表明没有蓝牙设备  
  29.                 if(adapter!=null){  
  30.                     System.out.println("本机拥有BlueTooth");  
  31.                     //调用isEnable方法,判断当前蓝牙是否可用  
  32.                         if(!adapter.isEnabled()){  
  33.                             //创建一个intent对象,。该对象用于启动蓝牙  
  34.                             Intent intent = new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE);  
  35.                             startActivity(intent);  
  36.                         }  
  37.                         //得到已经配对的蓝牙适配器对象  
  38.                     Set<BluetoothDevice> devices = adapter.getBondedDevices();  
  39.                         if(devices.size()>0){  
  40.                             for(Iterator<BluetoothDevice> iterator =devices.iterator();iterator.hasNext();){  
  41.                                 BluetoothDevice bluetoothDevice = (BluetoothDevice) iterator.next();      
  42.                                 //打印远程蓝牙设备的地址  
  43.                                 System.out.println(bluetoothDevice.getAddress());}  
  44.                         }  
  45.                 }else{  
  46.                     System.out.println("没有蓝牙设备");  
  47.                 }  
  48.             }  
  49.         });  
  50.     }  
  51. }  

布局文件就不给了,就一个button


记得配置

[html]  view plain copy print ?
  1. <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值