本文来自:安卓航班网

很多开发人员在最新的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蓝牙栈相关的以后再讲吧。

更多相关文章

  1. [转]Android中的BatteryService及相关组件
  2. S5PV210-uboot-fastboot原理
  3. android usb解析(二)UsbHostManager(and6.0)
  4. input subsystem
  5. Android清单文件中相关属性含义(Provider)
  6. 基于Cortex-A8的fs_s5pc100开发平台研发成功
  7. android 中文 api (72) ―― BluetoothSocket[蓝牙]
  8. [Android实例] android登录Web以及登录保持,cookie管理相关
  9. adb wifi连接手机

随机推荐

  1. [置顶] android 自定义ListView实现元素
  2. 【Android(安卓)开源系列】之网络请求框
  3. android 本地数据存贮之sharedpreference
  4. 【整理自慕课网】Android动感系列-扫一扫
  5. Android(第三种动画)属性动画完全解析(上),
  6. Android中视图View的深入理解及实例演示
  7. 用Android(安卓)Studio打开一个存在的Flu
  8. android主题与风格入门
  9. Android控件之Spinner用法详解
  10. Android(安卓)Java混淆(ProGuard)