bluecove堆栈完全关闭

时间:2017-08-03 09:17:15

标签: java mobile bluetooth pc bluecove

我是blueocve的新手,我正在bluecove通过netbeans java库找到我的基于Android的手机。我通过蓝牙配对我的手机和笔记本电脑,当我运行以下代码时,我得到了这个例外

bluecove堆栈关闭已完成,我无法在输出窗口中看到任何结果

我在winsock上使用bluecove 2.1.1快照....(赢得8.1 64位)

代码

package bluetooth;

import static java.sql.DriverManager.println;
import javax.bluetooth.*;

public class Bluetooth {
    public static Object lock=new Object();

    public static void main(String[] args) throws BluetoothStateException, InterruptedException{

        LocalDevice localdevice=LocalDevice.getLocalDevice();
        //localdevice.setDiscoverable(DiscoveryAgent.GIAC);

        DiscoveryAgent agent=localdevice.getDiscoveryAgent();

        agent.startInquiry(DiscoveryAgent.GIAC, new MyDiscoveryListener());

        synchronized(lock) {
            lock.wait();
        }
    }
}

===========================================

LISTENER

package bluetooth;

import static bluetooth.Bluetooth.lock;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import java.lang.System.*;
import static java.sql.DriverManager.println;

public class MyDiscoveryListener implements DiscoveryListener {

    public MyDiscoveryListener() {
    }

    @Override
    public void deviceDiscovered(RemoteDevice rd, DeviceClass dc) {
        //throw new UnsupportedOperationException("Not supported yet."); //To    change body of generated methods, choose Tools | Templates.
        String name="";

        try {
            name=rd.getFriendlyName(false);
            println("Friendly name is"+name);
        } catch (IOException ex) {
            name=rd.getBluetoothAddress();
            println("Bluetooth Adress is"+name);
        }
    }

    @Override
    public void servicesDiscovered(int i, ServiceRecord[] srs) {
        // throw new UnsupportedOperationException("Not supported yet."); //To    change body of generated methods, choose Tools | Templates.
        // println("discovered");
    }

    @Override
    public void serviceSearchCompleted(int i, int i1) {
        //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        //println("completed");
    }

    @Override
    public void inquiryCompleted(int i) {
        //throw new UnsupportedOperationException("Not supported yet."); //To  change body of generated methods, choose Tools | Templates.
        //println("completed");
        synchronized(lock){
            lock.notify();
        }
    }

}

0 个答案:

没有答案