Question

My problem is that i am not able to find the class of device and device services of my own bluetooth device. Though i am able to find the Connection State, MAC address and other info using the

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

I even tried accessing the Bluetooth folder in sys>devices>virtual path but this folder is not located in every device.

Could there be any way to fetch the bluetooth info by accessing the proc file system, if yes please help.

It is really strange that i am able to the bluetooth class of remote devices by fetching the

btAdapter.getBondedDevices();//Retruns the set of BluetoothDevice class

but i am not able to get device class of default(own) bluetooth.

Was it helpful?

Solution

Finally after a lot of struggling i found a way to find the services 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top