[英]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 中,我们有两个不同级别的公共方法:
public
keyword. public
关键字控制。@hide
annotation. @hide
注释控制。 A method is Android-level public if it does not have the @hide
annotation in its 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#createL2capChannel
和BluetoothAdapter#listenUsingL2capChannel
。 Note the name of the latter is different form listenUsingL2capOn
.请注意,后者的名称与
listenUsingL2capOn
不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.