티스토리 뷰
[Java] Bluetooth Examples for javax.bluetooth.DiscoveryAgent
jamezc 2015. 5. 18. 00:21Java Code Examples for javax.bluetooth.DiscoveryAgent
The following code examples are extracted from open source projects. You can click to vote up the examples you like. Your votes will be used in an intelligent system to get more and better code examples.
Code Example 1:
From project lego-mindstorms-praktikum, under directory /src/basis/.
Source BTRaceStartClient.java
public void searchForDevices(){ LocalDevice localDevice; DiscoveryAgent discoveryAgent; try { localDevice=LocalDevice.getLocalDevice(); discoveryAgent=localDevice.getDiscoveryAgent(); discoveryAgent.startInquiry(DiscoveryAgent.GIAC,this); } catch ( BluetoothStateException ex) { } }
Code Example 2:
From project j2mepolish, under directory /enough-polish-j2me/source/src/de/enough/polish/bluetooth/.
Source DiscoveryHelper.java
/** * Finds all nearby devices in the specified search mode * @param searchMode the search mode, either DiscoveryAgent.GIAC or DiscoveryAgent.LIAC. If in doubt use GIAC. * @param deviceClassMajor the major version of device classes that should be returned, -1 if all devices should be retrieved * @param deviceClassMinor the minor version of device classes that should be returned, -1 if all devices should be retrieved * @return an array of all found devices, can be empty but not null * @throws BluetoothStateException when there was an error during search */ private BluetoothDevice[] findDevicesImpl(int searchMode,int deviceClassMajor,int deviceClassMinor) throws BluetoothStateException { this.searchedClassMajor=deviceClassMajor; this.searchedClassMinor=deviceClassMinor; LocalDevice device=LocalDevice.getLocalDevice(); if (device == null) { return new BluetoothDevice[0]; } DiscoveryAgent discAgent=device.getDiscoveryAgent(); device.setDiscoverable(searchMode); synchronized (INSTANCE) { discAgent.startInquiry(searchMode,INSTANCE); try { INSTANCE.wait(); } catch ( InterruptedException e) { } } BluetoothDevice[] devices=new BluetoothDevice[INSTANCE.discoveredDevices.size()]; Arrays.cast(INSTANCE.discoveredDevices.getInternalArray(),devices); INSTANCE.discoveredDevices.clear(); return devices; }
Code Example 3:
From project j2mepolish, under directory /enough-polish-j2me/source/src/de/enough/polish/bluetooth/.
Source DiscoveryHelper.java
/** * Searches all nearby devices for a service with the specified UUID * @param ids the unique bluetooth identifiers of the service * @param attributes the attributes that should be queried, use null for not searching for any attributes * @param devices the devices that should be searched for the service * @return the first found service or null if none is found * @throws BluetoothStateException when the service search fails unexpectetly */ private ServiceRecord findServicesImpl(UUID[] ids,int[] attributes,Object[] devices) throws BluetoothStateException { LocalDevice localDevice=LocalDevice.getLocalDevice(); if (localDevice == null) { return null; } DiscoveryAgent discAgent=localDevice.getDiscoveryAgent(); for (int i=0; i < devices.length; i++) { Object obj=devices[i]; RemoteDevice remoteDevice=(obj instanceof RemoteDevice ? (RemoteDevice)obj : ((BluetoothDevice)obj).getDevice()); this.transctionId=discAgent.searchServices(attributes,ids,remoteDevice,this); synchronized (this) { try { wait(); } catch ( InterruptedException e) { } } if (this.discoveredServices.size() > 0) { break; } } if (this.discoveredServices.size() > 0) { ServiceRecord serviceRecord=(ServiceRecord)this.discoveredServices.get(0); this.discoveredServices.clear(); return serviceRecord; } return null; }
Code Example 4:
From project j2mepolish, under directory /enough-polish-sample-nutiteq/nutiteq_maps_lib_src_1_1_0/src/com/nutiteq/bluetooth/.
Source BluetoothAPIDevice.java
private void findDevices(){ try { btDevicesFound.removeAllElements(); isBTSearchComplete=false; final LocalDevice local=LocalDevice.getLocalDevice(); final DiscoveryAgent discoveryAgent=local.getDiscoveryAgent(); discoveryAgent.startInquiry(DiscoveryAgent.GIAC,this); while (!isBTSearchComplete) { synchronized (this) { this.wait(BLUETOOTH_TIMEOUT); } if (!isBTSearchComplete) { discoveryAgent.cancelInquiry(this); } } } catch ( final Exception e) { Log.error("BT: find " + e.getMessage()); Log.printStackTrace(e); } }
Code Example 5:
From project maps-lib-nutiteq, under directory /src/com/nutiteq/bluetooth/.
Source BluetoothAPIDevice.java
private void findDevices(){ try { btDevicesFound.removeAllElements(); isBTSearchComplete=false; final LocalDevice local=LocalDevice.getLocalDevice(); final DiscoveryAgent discoveryAgent=local.getDiscoveryAgent(); discoveryAgent.startInquiry(DiscoveryAgent.GIAC,this); while (!isBTSearchComplete) { synchronized (this) { this.wait(BLUETOOTH_TIMEOUT); } if (!isBTSearchComplete) { discoveryAgent.cancelInquiry(this); } } } catch ( final Exception e) { Log.error("BT: find " + e.getMessage()); Log.printStackTrace(e); } }
Code Example 6:
From project colloqmote, under directory /Computer/ColloQmoteAccelerometerPC/src/.
Source Bluetooth.java
private DiscoveryAgent getAgent(){ try { return LocalDevice.getLocalDevice().getDiscoveryAgent(); } catch ( BluetoothStateException e) { log(e); log("ERROR detected and all operations stopped."); throw new Error("No discovery agent available."); } }
Code Example 7:
From project colloqmote, under directory /Computer/ColloQmoteKeypadPC/src/.
Source Bluetooth.java
private DiscoveryAgent getAgent(){ try { return LocalDevice.getLocalDevice().getDiscoveryAgent(); } catch ( BluetoothStateException e) { log(e); log("ERROR detected and all operations stopped."); throw new Error("No discovery agent available."); } }
Code Example 8:
From project colloqmote, under directory /Mobile/ColloqmoteAccelerometer/build/preprocessed/.
Source Bluetooth.java
protected void startApp() throws MIDletStateChangeException { display=Display.getDisplay(this); display.setCurrent(infoArea); infoArea.deleteAll(); try { LocalDevice device=LocalDevice.getLocalDevice(); device.setDiscoverable(DiscoveryAgent.GIAC); String url="btspp://localhost:" + UUID + ";name=DeviceServerCOMM"; log("Create server by uri: " + url); StreamConnectionNotifier notifier=(StreamConnectionNotifier)Connector.open(url); serverLoop(notifier); } catch ( Throwable e) { log(e); } }
Code Example 9:
From project colloqmote, under directory /Mobile/ColloqmoteAccelerometer/src/.
Source Bluetooth.java
protected void startApp() throws MIDletStateChangeException { display=Display.getDisplay(this); display.setCurrent(infoArea); infoArea.deleteAll(); try { LocalDevice device=LocalDevice.getLocalDevice(); device.setDiscoverable(DiscoveryAgent.GIAC); String url="btspp://localhost:" + UUID + ";name=DeviceServerCOMM"; log("Create server by uri: " + url); StreamConnectionNotifier notifier=(StreamConnectionNotifier)Connector.open(url); serverLoop(notifier); } catch ( Throwable e) { log(e); } }
Code Example 10:
From project colloqmote, under directory /Mobile/ColloQmoteKeypad/build/preprocessed/.
Source Bluetooth.java
void initSensor(){ infoArea.deleteAll(); display.setCurrent(infoArea); try { LocalDevice device=LocalDevice.getLocalDevice(); device.setDiscoverable(DiscoveryAgent.GIAC); String url="btspp://localhost:" + UUID + ";name=DeviceServerCOMM"; log("Create server by uri: " + url); StreamConnectionNotifier notifier=(StreamConnectionNotifier)Connector.open(url); serverLoop(notifier); } catch ( Throwable e) { log(e); } }
Code Example 11:
From project colloqmote, under directory /Mobile/ColloQmoteKeypad/src/.
Source Bluetooth.java
void initSensor(){ infoArea.deleteAll(); display.setCurrent(infoArea); try { LocalDevice device=LocalDevice.getLocalDevice(); device.setDiscoverable(DiscoveryAgent.GIAC); String url="btspp://localhost:" + UUID + ";name=DeviceServerCOMM"; log("Create server by uri: " + url); StreamConnectionNotifier notifier=(StreamConnectionNotifier)Connector.open(url); serverLoop(notifier); } catch ( Throwable e) { log(e); } }
Code Example 12:
From project Eclipse, under directory/com.mobilesorcery.sdk.ui.targetphone/src/com/mobilesorcery/sdk/ui/targetphone/internal/bt/.
Source BluetoothDialog.java
public void discoverDevices(){ clearDevices(); updateUI(); LocalDevice dongle=null; try { dongle=LocalDevice.getLocalDevice(); agent=dongle.getDiscoveryAgent(); agent.startInquiry(DiscoveryAgent.GIAC,this); } catch ( BluetoothStateException e) { setRefreshInProgress(false); Policy.getStatusHandler().show(new Status(IStatus.ERROR,TargetPhonePlugin.PLUGIN_ID,e.getMessage()),"Could not scan for devices"); } }
Code Example 13:
From project emergency-service-drools-app, under directory /emergency-service-sensor/src/main/java/com/wordpress/salaboy/sensor/wii/.
Source MyMoteFinder.java
public void startDiscovery(){ try { discoveryAgent.startInquiry(DiscoveryAgent.LIAC,listener); } catch ( BluetoothStateException ex) { throw new RuntimeException(ex); } }
Code Example 14:
From project Gome, under directory /sources/com/indigonauts/gome/multiplayer/bt/.
Source Discoverer.java
public Vector findOtherGome(){ RemoteDevice[] devList=null; try { agent.startInquiry(DiscoveryAgent.GIAC,this); synchronized (this) { try { this.wait(); } catch ( Exception e) { } } } catch ( BluetoothStateException e) { System.out.println("Unable to find devices to search"); } if (deviceList.size() > 0) { devList=new RemoteDevice[deviceList.size()]; deviceList.copyInto(devList); System.out.println("calling ss"); searchServices(devList); return serviceList; } log.info("No Devices found."); log.info("No Services found."); return serviceList; }
Code Example 15:
From project j2mepolish, under directory /enough-polish-build/source/src/de/enough/polish/rmi/bluetooth/.
Source L2CapServer.java
/** * Generates the URL that fits for the given UUID * @param uuid the UUID * @return the local connection URL for establishing an L2CAP based service * @throws BluetoothStateException when the URL could not be generated */ public static String generateLocalUrl(String uuid) throws BluetoothStateException { LocalDevice device=LocalDevice.getLocalDevice(); device.setDiscoverable(DiscoveryAgent.GIAC); String url="btl2cap://localhost:" + uuid; String max=LocalDevice.getProperty("bluetooth.l2cap.receiveMTU.max"); if (max != null) { if (max.equals("0")) { max="762"; } url+=";ReceiveMTU=" + max + ";TransmitMTU="+ max; } return url; }
Code Example 16:
From project Remote-Bluetooth-Android, under directory/RemoteBluetoothServer/src/com/luugiathuy/apps/remotebluetooth/.
Source WaitThread.java
/** * Waiting for connection from devices */ private void waitForConnection(){ LocalDevice local=null; StreamConnectionNotifier notifier; StreamConnection connection=null; try { local=LocalDevice.getLocalDevice(); local.setDiscoverable(DiscoveryAgent.GIAC); UUID uuid=new UUID("04c6093b00001000800000805f9b34fb",false); System.out.println(uuid.toString()); String url="btspp://localhost:" + uuid.toString() + ";name=RemoteBluetooth"; notifier=(StreamConnectionNotifier)Connector.open(url); } catch ( BluetoothStateException e) { System.out.println("Bluetooth is not turned on."); e.printStackTrace(); return; } catch ( IOException e) { e.printStackTrace(); return; } while (true) { try { System.out.println("waiting for connection..."); connection=notifier.acceptAndOpen(); Thread processThread=new Thread(new ProcessConnectionThread(connection)); processThread.start(); } catch ( Exception e) { e.printStackTrace(); return; } } }
Code Example 17:
From project Sphero-Desktop-API, under directory /bluecove/com/intel/bluetooth/.
Source BluetoothStackBlueSoleil.java
/** * There are no functions to find BlueSoleil discoverable status. */ public int getLocalDeviceDiscoverable(){ if (isBluetoothReady(2)) { return DiscoveryAgent.GIAC; } else { return DiscoveryAgent.NOT_DISCOVERABLE; } }
Code Example 18:
From project Sphero-Desktop-API, under directory /bluecove/com/intel/bluetooth/.
Source BluetoothStackMicrosoft.java
public boolean setLocalDeviceDiscoverable(int mode) throws BluetoothStateException { switch (mode) { case DiscoveryAgent.NOT_DISCOVERABLE: cancelLimitedDiscoverableTimer(); DebugLog.debug("setDiscoverable(false)"); setDiscoverable(false); return (DiscoveryAgent.NOT_DISCOVERABLE == getLocalDeviceDiscoverable()); case DiscoveryAgent.GIAC: cancelLimitedDiscoverableTimer(); DebugLog.debug("setDiscoverable(true)"); setDiscoverable(true); return (DiscoveryAgent.GIAC == getLocalDeviceDiscoverable()); case DiscoveryAgent.LIAC: cancelLimitedDiscoverableTimer(); DebugLog.debug("setDiscoverable(LIAC)"); setDiscoverable(true); if (!(DiscoveryAgent.GIAC == getLocalDeviceDiscoverable())) { return false; } limitedDiscoverableTimer=Utils.schedule(60 * 1000,new Runnable(){ public void run(){ try { setDiscoverable(false); } catch (BluetoothStateException e) { DebugLog.debug("error setDiscoverable",e); } finally { limitedDiscoverableTimer=null; } } } ); return true; } return false; }
Code Example 19:
From project Sphero-Desktop-API, under directory /bluecove/com/intel/bluetooth/.
Source BluetoothStackMicrosoft.java
public int getLocalDeviceDiscoverable(){ int mode=getBluetoothRadioMode(); if (mode == BTH_MODE_DISCOVERABLE) { if (limitedDiscoverableTimer != null) { DebugLog.debug("Discoverable = LIAC"); return DiscoveryAgent.LIAC; } else { DebugLog.debug("Discoverable = GIAC"); return DiscoveryAgent.GIAC; } } else { DebugLog.debug("Discoverable = NOT_DISCOVERABLE"); return DiscoveryAgent.NOT_DISCOVERABLE; } }
Code Example 20:
From project Sphero-Desktop-API, under directory /bluecove/com/intel/bluetooth/.
Source BluetoothStackOSX.java
public int getLocalDeviceDiscoverable(){ if (getLocalDeviceDiscoverableImpl()) { return DiscoveryAgent.GIAC; } else { return DiscoveryAgent.NOT_DISCOVERABLE; } }
'Computer > JAVA' 카테고리의 다른 글
[JAVA] ArrayList - Java API (0) | 2017.02.27 |
---|---|
Java 문자열 숫자 자료형 변환 (0) | 2016.11.14 |
JNA (Java Native Access) (0) | 2015.03.14 |
[JAVA] 자바 실행파일 만들기 (0) | 2015.03.01 |
JGoodies JAVA Swing API (0) | 2015.02.07 |