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
相关解决方案
- 小弟我想做一个多功能web service client
- 请问registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister
- Servlet.service() for servlet [jsp] in context with path解决方案
- web service 第一天接触不懂 仍是那个访问天气预报的例子 代码很简单
- DBCP borrowObject failed: java.sql.SQLException: Io 错误: The Network Adapter
- Web Service 错误:服务器未能识别 HTTP 头 SOAPAction 的值: http://tempuri.org/
- Server Apache Tomcat v6.0.35 at localhost failed to start
- web service No services have been found.解决方法
- Context [] startup failed due to previous errors解决方案
- 学习Web Service,用哪种框架好?AXIS,XFire,CXF?该如何处理
- java service 项目有关问题
- 对象集,数组,web service,该怎么解决
- log4j:ERROR setFile(null,false) call failed.解决方法
- org.apache.catalina.core.ApplicationDispatcher invoke Servlet.service() for se解决思路
- CAS(SSO) tomcat ssl 配置出错 PKIX path building failed,该怎么处理
- Eclipse 报错org.apache.catalina.LifecycleException: Failed to start component。该怎么解决
- JMS:Java讯息服务(Java Message Service)初学笔记
- 新手学习j2me,请教调用.net service 时用ksoap,还是用JSR172好
- \nbproject\build-impl.xml:332: Preverification failed with error code 1. 异常
- org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryV
- websphere5.12 Error 503: Failed to load target servlet [action],该如何处理
- 严重: Context [/ZZVC_HOMEPAGE] startup failed due to previous errors
- method failed; nested exception is org.hibernate.HibernateException:
- httpClient 错误 The server failed to respond with a valid HTTP response
- WCF service 下传订单文件到ftp
- FCIAddFile(failed: code 一 [Failure opening file to be stored in cabinet]
- FCIAddFile(failed: code 1 [Failure opening file to be stored in cabinet],该怎么解决
- 请教:有人开发过OPOS驱动吗,撰写 service object?
- vc写的 windows service 控制台程序有关问题
- Failed to open XML file解决方案