bluecove stack shutdown completely

我的未来我决定 提交于 2019-12-11 07:07:58

问题


I am new to blueocve and I am working on finding my android based phone via bluecove java library in netbeans. I paired my phone and laptop via bluetooth and when I run the below code I get this exception

bluecove stack shutdown completed and I can't see any result in output window

I use bluecove 2.1.1 snapshot on winsock....(win 8.1 64 bit)

below code

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();
        }
    }

}

来源:https://stackoverflow.com/questions/45479907/bluecove-stack-shutdown-completely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!