简体   繁体   English

为什么 android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) 无法访问?

[英]Why is android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) not accessible?

This might be a newbie question since my experience with Android is limited but for some reason I'm unable to access the method android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) .这可能是一个新手问题,因为我对 Android 的经验有限,但由于某种原因,我无法访问方法android.bluetooth.BluetoothAdapter#listenUsingL2capOn(int) It seems to be public and hence not really sure why the symbol is not being recognized.它似乎是公开的,因此不确定为什么该符号未被识别。 And on a side note how does one open up L2CAP bluetooth socket server on android?另一方面,如何在 android 上打开 L2CAP 蓝牙套接字服务器? Only one question I found somewhat related to this - How can I instantiate a L2Cap socket in Android?我发现只有一个与此相关的问题 - 如何在 Android 中实例化 L2Cap 套接字? . . Any help would be appreciated.任何帮助,将不胜感激。

In Android we have two different levels of public methods:在 Android 中,我们有两个不同级别的公共方法:

  • Java-level public: This is controlled by the public keyword. Java 级别的 public:这由public关键字控制。
  • Android-level public: This is controlled by the @hide annotation. Android 级别的公共:这由@hide注释控制。 A method is Android-level public if it does not have the @hide annotation in its JavaDoc.如果一个方法在其 JavaDoc 中没有@hide注释,则它是 Android 级别的公共方法。

If a method is Java-level public, but not Android-level public, this means it can only be used within the Android framework code, but not by app code.如果一个方法是 Java 级别的 public,而不是 Android 级别的 public,这意味着它只能在 Android 框架代码中使用,而不能在应用程序代码中使用。 This is needed to keep the Android API as small as possible: When Android developers add a helper method that is useful in many places within the Android framework code, they would want this method to be Java-level public, so that it can be used by the other classes in the Android framework code. This is needed to keep the Android API as small as possible: When Android developers add a helper method that is useful in many places within the Android framework code, they would want this method to be Java-level public, so that it can be used由 Android 框架代码中的其他类。 However, the Android developers might not want this helper method to be used by app code, because then if they later rework the code and the helper method is no longer needed, removing the method would break the apps using it.但是,Android 开发人员可能不希望应用程序代码使用此辅助方法,因为如果他们以后重新编写代码并且不再需要辅助方法,删除该方法会破坏使用它的应用程序。 Not making the method Android-level public gives the Android developers more freedom to change/remove the method later on.不公开 Android 级别的方法为 Android 开发人员提供了更多的自由,以便以后更改/删除该方法。

Considering for example the method you gave: listenUsingL2capOn has the @hide annotation, as can be seen here .例如,考虑您提供的方法: listenUsingL2capOn具有@hide注释,如此处所示 Therefore, it is not considered Android-level public.因此,它不被认为是Android级别的公开。 You can also see this from the API documentation of BluetoothAdapter , which does not list the methods that are not Android-level public ( link ).您也可以从BluetoothAdapter的 API 文档中看到这一点,该文档没有列出非 Android 级别公共的方法( 链接)。

Regarding your side question: I'm not familiar with how to create a L2CAP bluetooth socket server in Android, but the answer that you linked looks promising.关于您的附带问题:我不熟悉如何在 Android 中创建 L2CAP 蓝牙套接字服务器,但是您链接的答案看起来很有希望。 Eg using BluetoothDevice#createL2capChannel and BluetoothAdapter#listenUsingL2capChannel .例如使用BluetoothDevice#createL2capChannelBluetoothAdapter#listenUsingL2capChannel Note the name of the latter is different form listenUsingL2capOn .请注意,后者的名称与listenUsingL2capOn不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Xamarin.android 中的 BluetoothAdapter 执行蓝牙扫描 - Perform a bluetooth scan with BluetoothAdapter in Xamarin.android Android-ClassCastException-BluetoothManager无法强制转换为android.bluetooth.BluetoothAdapter错误 - Android - ClassCastException - BluetoothManager cannot be cast to android.bluetooth.BluetoothAdapter Error 为什么BluetoothAdapter.startDiscovery(..)需要广播蓝牙设备? - Why BluetoothAdapter.startDiscovery(..) require to get Bluetooth device broadcast? 使用通过ListAdapter或BluetoothAdapter找到的大量蓝牙设备更新Android中的TextView - Update TextView in Android with amount of bluetooth devices found via ListAdapter or BluetoothAdapter java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser - java.lang.NoSuchMethodError: android.bluetooth.BluetoothAdapter.getBluetoothLeAdvertiser 通过BluetoothAdapter将蓝牙与getRemoteDevice()连接 - Connect bluetooth with getRemoteDevice() from BluetoothAdapter E / BluetoothAdapter:蓝牙活页夹为空 - E/BluetoothAdapter: Bluetooth binder is null Android BLE 蓝牙适配器状态 - Android BLE BluetoothAdapter States 取消绑定蓝牙设备时的BluetoothAdapter通知 - BluetoothAdapter notification when a bluetooth device is unboded Android BluetoothAdapter getRemoteDevice已缓存 - Android BluetoothAdapter getRemoteDevice is cached
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM