Java examples for javax.bluetooth:RemoteDevice
get bluetooth Service Class
/*/*from w w w . ja va2 s. c o m*/ * $HeadURL$ * * * Copyright (c) 2001-2008 Motorola, Inc. All rights reserved. * * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * Revision History: * * Date Author Comment * --------------------------------------------------------------------------------- * Oct 15,2006 Motorola, Inc. Initial creation * */ import javax.bluetooth.DeviceClass; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.DiscoveryListener; import javax.bluetooth.LocalDevice; import javax.bluetooth.RemoteDevice; import javax.bluetooth.ServiceRecord; import javax.bluetooth.UUID; public class Main{ public static void main(String[] argv) throws Exception{ String btAddress = "java2s.com"; int timeout = 2; System.out.println(getServiceClass(btAddress,timeout)); } public static int getServiceClass(final String btAddress, final int timeout) { LocalDevice device; DiscoveryAgent da; DiscoveryListenerImpl listen; DeviceClass deviceClass; try { Boolean synch = new Boolean(true); listen = new DiscoveryListenerImpl(synch, btAddress); device = LocalDevice.getLocalDevice(); da = device.getDiscoveryAgent(); if (!da.startInquiry(DiscoveryAgent.GIAC, listen)) { return -1; } synchronized (synch) { try { // the default maximum time allocated for querying the remote // device is one minute if the config timeout is not set by the user. // User can adjust this time by setting the timeout. synch.wait(timeout * 30); } catch (Exception e) { e.printStackTrace(); return -1; } } } catch (Throwable th) { System.out.println("Error : " + th); return -1; } if (listen.getType() != DiscoveryListener.INQUIRY_COMPLETED) { return -1; } deviceClass = listen.getDeviceClass(); if (deviceClass != null) { return deviceClass.getServiceClasses(); } return -1; } }