⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 devicediscoverer.java

📁 蓝牙 Obex 源码 J2me 初学者必须的东西
💻 JAVA
字号:
import javax.bluetooth.*;
import java.util.*;

public class DeviceDiscoverer implements DiscoveryListener {
    
	FileClient client;
	Vector remoteDevices = new Vector();
	
	DiscoveryAgent discoveryAgent;
    
	public DeviceDiscoverer(FileClient client) {
		this.client = client;
		try {
			LocalDevice localDevice = LocalDevice.getLocalDevice();
			discoveryAgent = localDevice.getDiscoveryAgent();

			client.updateStatus("[client:] LocalDevice properties: " + localDevice.getFriendlyName() + " (" + localDevice.getBluetoothAddress() + ")");
			client.updateStatus("[client:] Searching for Bluetooth devices in the vicinity...");
			discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);

		} catch(Exception e) {
			e.printStackTrace();
		}
	}
    
    
   
	public void deviceDiscovered(RemoteDevice remoteDevice, DeviceClass cod) {

		try{
	            remoteDevices.addElement(remoteDevice);
			client.updateStatus("[client:] New device discovered : "  + remoteDevice.getFriendlyName(true)+ " (" + remoteDevice.getBluetoothAddress() + ")" );

		} catch(Exception e){
			e.printStackTrace();
		}	

	}

    
	public void inquiryCompleted(int discType) {
		String inqStatus = null;
        
		if (discType == DiscoveryListener.INQUIRY_COMPLETED) {
			inqStatus = "[client:] Inquiry completed";            
		} else if (discType == DiscoveryListener.INQUIRY_TERMINATED) {
			inqStatus = "[client:] Inquiry terminated";
		} else if (discType == DiscoveryListener.INQUIRY_ERROR) {
			inqStatus = "[client:] Inquiry error";
		}
        
		client.updateStatus(inqStatus);
		client.serviceButton.setEnabled(true);
		client.deviceButton.setEnabled(false);
	}

    public void servicesDiscovered(int transID, ServiceRecord[] servRecord){}
    
    public void serviceSearchCompleted(int transID, int respCode) {}
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -