package com.test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import android.app.Activity;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
public class Other extends Activity {
public static final UUID MyUUID = UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB");
private BluetoothSocket btSocket = null;
private BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();// 获取蓝牙设备
private Set<BluetoothDevice> devices = null;
private BluetoothDevice device;
private BluetoothDevice btDev;
private ProgressDialog bluetoothPro;
private boolean bluetoothstause = true;
private Intent recalled;
private connectbluetooth connectdevice = null;
private volatile boolean _discoveryFinished;
private discover myDiscovery = new discover();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
// 获取当前已经配对的设备
devices = adapter.getBondedDevices();
// 创建一个进度条
bluetoothPro = new ProgressDialog(this);
// 如果已配对的设备大于0 就查找到目标设备并且开始连接 如果没有找到到设备就开始搜索
if (devices.size() > 0) {
int cnt = 0;
for (Iterator<BluetoothDevice> it = devices.iterator(); it
.hasNext();) {
device = (BluetoothDevice) it.next();
if (device.getName().equals("PC-60NW")) {
cnt++;
bluetoothConnect(device);
break;
}
}
if (cnt == 0) {
// 没有以配对设备 开始搜索
System.out.println("配对设备中没有找到目标设备 开始搜索");
Discovery();
}
} else {
// 没有以配对设备 开始搜索
System.out.println("没有以配对设备 开始搜索");
Discovery();
}
}
// 搜索设备开始的函数
public void Discovery() {
/* 注册接收器 */
IntentFilter discoveryFilter = new IntentFilter(
BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
registerReceiver(_discoveryReceiver, discoveryFilter);
IntentFilter foundFilter = new IntentFilter(
BluetoothDevice.ACTION_FOUND);
registerReceiver(_foundReceiver, foundFilter);
// 再次去确定蓝牙设备状态
if (!adapter.isEnabled()) {
adapter.enable();
}
// 设置进度条显示的提示信息
bluetoothPro.setMessage("Discovery...");
bluetoothPro.show();
// 启动线程开始搜索设备
myDiscovery.start();
}
// 在线程中搜索设备
public class discover extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
adapter.startDiscovery();
for (;;) {
详细解决方案
各位兄弟姐妹帮忙看看 蓝牙连接错误Service discovery failed
热度:160 发布时间:2016-05-01 10:48:30.0
相关解决方案
- 请问registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister
- Servlet.service() for servlet [jsp] in context with path解决方案
- 学习Web Service,用哪种框架好?AXIS,XFire,CXF?该如何处理
- java service 项目有关问题
- 对象集,数组,web service,该怎么解决
- 新手学习j2me,请教调用.net service 时用ksoap,还是用JSR172好
- \nbproject\build-impl.xml:332: Preverification failed with error code 1. 异常
- websphere5.12 Error 503: Failed to load target servlet [action],该如何处理
- 请教:有人开发过OPOS驱动吗,撰写 service object?
- vc写的 windows service 控制台程序有关问题
- 请教一上有没有C++调用WEB SERVICE 做成DLL的例子
- vs2008中怎么使用vc++构建web service
- 客户端用vc2005的c++来编写,web service 只是连接就报错解决方法
- Reporting Service 报表订阅 到win2003 系统的有关问题
- c#中,运作程序时,提示mysql.data load failed
- Reporting Service 分组排列有关问题
- Silverlight学习数据跟RIA服务时,找不到domain service class模板
- asp reporting service 只显示一起,大神进
- !AJAX的autocompleteextender控件实现自动输入一定需要Web Service
- 无法打开登录所请求的数据库 "xxx"登录失败用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败解决方案
- |zyciis| C# 怎么制作 Windows2003 IIS6 和 Meida Service 的自动安装程序
- “LINQ”提供“Service”服务的疑问解决办法
- 关于web service 的一些疑问?该如何解决
- ASP.NET State Service (ASP.NET 状态服务) 找不到,该如何解决
- 怎么在web程序里控制windows service
- 对调用web service 是用是soap好还是HTTP POST好?解决方案
- failed to render the page 水晶报表出错,该如何处理
- ASP.NET 2.0能否使用Reporting Service for SQL Server 2000,该如何解决
- 关于 Web Service 中的Socket的有关问题 急求高手帮忙
- 关于web service 安全有关问题