1

I am creating a application in which one module is there where i want to retrieve the services supported by my own Bluetooth device... Currently i am able to fetch the UUID of remote devices, by i havent found out any way to retrieve the UUID of my own device.

Thanks in advance

Karan_Rana
  • 2,813
  • 2
  • 26
  • 35

1 Answers1

0

Finally after a lot of struggling i found a way to find the UUID of own bluetooth device. Sdptool provides the interface for performing SDP queries on Bluetooth devices, and administering a local sdpd. Code snippet for it is follows:This code will only work in devices with root access.

try {
          System.setOut(new PrintStream(new FileOutputStream("/mnt/sdcard/abc.txt")));
          System.out.println("HelloWorld1");
          Process p;
          p = Runtime.getRuntime().exec(new String[] { "su", "-c","sdptool", "browse", "local" });
          BufferedReader stdInput = new BufferedReader(new InputStreamReader(
                  p.getInputStream()));
          String s;
          String res = "";
          while ((s = stdInput.readLine()) != null) {
              if(s.contains(""))
              System.out.println(s);
              Log.e("above -----", s);
          }
          p.destroy();
          return res;
      } catch (Exception e) {
          e.printStackTrace();
      }

and in case you want to discover the services of another Bluetooth device then you can replace "local" with the MAC address of the remote device.

Or you can also try running the sdp tool usinf adb shell as follows:

adb shell sdptool browse local

Karan_Rana
  • 2,813
  • 2
  • 26
  • 35
  • Karan_Rana, on which android release did you tried sdptool ? I want to know if its works on JB as from JB onwards bluez is replaced by broadcomm stack and sdptool is a part of bluez – ashish Apr 29 '13 at 04:15
  • Yes this would not be available in JB i am using it on ICS – Karan_Rana Apr 29 '13 at 06:23