0

我想从基于窗口的 java swing 应用程序将 JSON 数据发送到移动设备。我的应用程序能够成功搜索设备,但现在我需要建立与移动设备和应用程序的连接。我怎样才能建立连接?

public class BluetoothFinder {

public static final Vector<RemoteDevice> devicesDiscovered = new Vector<RemoteDevice>();
Object bluetoothName;

     public void BluetoothDeviceSearch() {
    final Object inquiryCompletedEvent = new Object();

    devicesDiscovered.clear();
    DiscoveryListener listener = new DiscoveryListener() {

        @Override
        public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
            System.out.println("Device " + btDevice.getBluetoothAddress() + " found");
            devicesDiscovered.addElement(btDevice);
            try {
                System.out.println("     name " + btDevice.getFriendlyName(false));
                bluetoothName = btDevice.getFriendlyName(false);
            } catch (IOException cantGetDeviceName) {
            }
        }
}

void printResult() {
    System.out.println("PrintResult method Taget Hit ..." + devicesDiscovered.size() + " device(s) found " + "New " + devicesDiscovered);
    System.out.println("Printing ...");

    Enumeration bluetoothDevicesList = devicesDiscovered.elements();
    while (bluetoothDevicesList.hasMoreElements()) {
        Object result = (Object) bluetoothDevicesList.nextElement();
        System.out.println("Bluetooth Device " + result);

        if (result.toString().equals("CC051B9C88DF")) {

            JOptionPane.showMessageDialog(null, "Bluetooth Device Name : '" + bluetoothName + "' Bluetooth Device No : '" + result + "'",
                    "Bluetooth Devices Search Result", 1);
        }

    }



    public static void main(String[] args) {
    BluetoothFinder bluetoothFinder = new BluetoothFinder();
    bluetoothFinder.BluetoothDeviceSearch();
    bluetoothFinder.printResult();
    }
}

上面的代码能够搜索设备,但我不知道如何与window OS和android mobile建立连接。

4

1 回答 1