【问题标题】:Android Strange bluetooth issue either in API or i m missing somethingAPI中的Android Strange蓝牙问题或我遗漏了一些东西
【发布时间】:2013-04-28 17:39:20
【问题描述】:

我的问题是我无法找到我自己的蓝牙设备的设备类别和设备服务。虽然我可以使用

找到连接状态、MAC 地址和其他信息
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

我什至尝试访问 sys>devices>virtual 路径中的蓝牙文件夹,但该文件夹并非位于每个设备中。

有没有办法通过访问proc文件系统来获取蓝牙信息,如果可以,请帮忙。

真的很奇怪,我可以通过获取蓝牙类的远程设备

btAdapter.getBondedDevices();//返回蓝牙设备类的集合

但我无法获得默认(自己的)蓝牙设备类。

【问题讨论】:

    标签: android bluetooth procfs


    【解决方案1】:

    经过一番苦苦挣扎,我终于找到了一种找到自己蓝牙设备服务的方法。 Sdptool 提供了在蓝牙设备上执行 SDP 查询和管理本地 sdpd 的接口。代码 sn-p 如下:此代码仅适用于具有 root 访问权限的设备。

    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();
          }
    

    如果您想发现另一个蓝牙设备的服务,您可以将“本地”替换为远程设备的 MAC 地址。

    或者你也可以尝试运行sdp工具usinf adb shell,如下:

    > adb shell sdptool 浏览本地

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-12
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 2019-03-12
      相关资源
      最近更新 更多