Android蓝牙栈bluez使用方法
来源:互联网 发布:caffe 提取所有参数 编辑:程序博客网 时间:2024/05/21 05:58
很多开发人员在最新的Android 0.9 SDK中没有找到蓝牙栈相关的参考,不过在官方消息中我们已经看到了是采用的是org.bluez相关的Package。这里主要介绍下Android蓝牙SDP相关的例程,我们看到是.intent.action,分为4个阶段:
org.bluez.intent.action.DISCOVERY_STARTED 开始探测
org.bluez.intent.action.REMOTE_DEVICE_FOUND 远程设备找到
org.bluez.intent.action.REMOTE_NAME_UPDATED 获取远程设备名称
org.bluez.intent.action.DISCOVERY_COMPLETED 完成SDP
大概的使用方法如下,在开发板上可以测试下,首先移植下org.bluez库
public void onStart(int startId, Bundle args)
{
super.onStart( startId, args );
try{
IBluetoothService ibtservice = BluetoothServiceNative.getBluetoothService(); //获取一个实例,其实在Android中已经准备好了系统服务
if( ibtservice == null ) {
stopSelf(); //失败了就Exit
return;
}
manager=ibtservice.getManager();
if( manager == null ) {
stopSelf();
}
if(! ibtservice.isBluetoothStarted()){
ibtservice.startBluetooth(); //开始服务
}
miadapter=manager.getDefaultAdapter();
miadapter.startDiscovery(); //准备探测了
String[] dispositivos=miadapter.listRemoteDevices(); //远程设备mac列表
if (dispositivos.length==0){
Toast.makeText(this, R.string.no_found_devices, Toast.LENGTH_SHORT).show(); //没有找到蓝牙设备
}else{
for (int i=0; i<dispositivos.length;i++){
//已经找到的蓝牙设备,准备配对然后干什么就看你自己了,当然比如获取设备类型是handset、ftp还是别的,根据Mac可以初步判断,当然标准GPS会使用串口来通讯。
}
}
}catch(Exception e){
System.out.println(e.getMessage());
}
}
打开通讯后可以导入下面的类
import org.bluez.Manager;
import org.bluez.Adapter;
import org.bluez.IBluetoothService;
import org.bluez.BluetoothServiceNative;
具体的Android蓝牙栈相关的以后再讲吧。
- Android蓝牙栈bluez使用方法
- 蓝牙 Bluez
- bluez/obex蓝牙协议栈编程
- bluez/obex蓝牙协议栈编程
- ARM平台移植蓝牙协议栈Bluez
- 蓝牙协议栈Bluez的移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- Android平台开发-Bluez function porting-蓝牙功能移植
- android蓝牙使用方法
- android蓝牙4.0使用方法
- linux蓝牙编程 bluez
- bluez蓝牙协议
- 蓝牙BlueZ的移植
- ubuntu蓝牙bluez
- 蓝牙协议栈bluez移植到pxa270上
- ClearCase完全攻略(五) UCM实例:创建PVOB,创建VOB,两者区分
- WinCE 程序设计 窗口管理函数
- 常用内存数据库介绍(一)
- MINI2440 LED驱动的汇编语言实现
- 网络游戏运营策略分析
- Android蓝牙栈bluez使用方法
- Log4net学习心得
- filter实现登录验证,并且过滤servlet
- VS2010帮助查看器推荐
- PowerDesigner中设置Hibernate一对多,多对一属性
- 如何使用netfilter/iptables构建防火墙
- select多路事件分离函数
- java 转中文数字
- Linux/Ubuntu 下编译安装 Subversion-1.6.9 (svn) 全攻略!