I see that a Bluetooth socket can be of type TYPE_L2CAP, but the constructor for BluetoothSocket seems to be private and I can only find a method to instantiate a socket of type RFCOMM. How can I obtain and use a L2CAP socket? Is it actually supported by Android?
How can I instantiate a L2Cap socket in Android?
8.7k Views Asked by nsndvd At
1
There are 1 best solutions below
Related Questions in ANDROID
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Related Questions in BLUETOOTH
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Related Questions in BLUETOOTH-LOWENERGY
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Related Questions in L2CAP
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
UPDATE 10/2019
Support is there! Enjoy the new API:
UPDATE 03/2019 With the first Android Q beta out there it looks like support is finally coming. https://developer.android.com/sdk/api_diff/q-beta1/changes.html
UPDATE 10/2018
Got info that L2CAP CoC will be supported starting from Android Q.
Unfortunately I'm unable to cite official sources for that.
OLD ANSWER
I'll post my own results, hoping to help others and maybe get hints if I am missing something.
TL;DR: Looks like I can't
No way to get a L2CAP CoC socket with public API
This page from the Android documentation claims that “LE Connection-Oriented Channels” (l2cap channels) are available since Android 8.0. In the Android API there is a
BluetoothSocket
class that can have typeL2_CAP
. But there is no way to get a BluetoothSocket instance with such type, due to the private visibility of the elements of that class. That’s it for the public Android java API: stuck.So?
Digging under the surface of the public java API. The source code for the android version 8+ offers a way to get a l2cap socket that is evolving in time:
createL2capSocket
method in android 8 (source)createL2capCoCSocket
method in android 9 (source)createL2capChannel
in the master branch of the android project (future release I guess?) (source)But in each released version this code is marked with the
@hide
annotation, which means that none of these methods is actually available for usage.Before Android 9 hidden methods were at least accessible, on some devices, with java reflection. That’s how we were able to test on android 8, with awful results.
Since version 9 of the OS this is not possible anymore: the platform actively blocks attempts to improperly access APIs.
Moreover..
Beside the fact that the methods to instantiate a socket are not visible, there is evidence of the immaturity of the API also in the lack of methods to tune parameters of the l2cap connection.
Going native?
I don't have experience with NDK but I think it would be possible to write c code to exploit the same low level functions used by the hidden methods. Unless android is not blocking that kind of usage as well, which is likely. Also this usage would conflict with regular usages of the bluetooth stack on a phone: normal usages are normally all filtered by an Android service. Bypassing this service would lead to unpredictable consequences, and it’s not suitable for a productive app.
Wrap it up
Testing on Android 8.1 with reflection led to very unsatisfying results. The claim that “LE Connection-Oriented Channels” are available since Android 8.0 just can’t be confirmed, despite the efforts.
In newer versions, the hidden methods for creating l2cap channels are evolving, and recently the hide annotation was removed. It’s hard to tell what this means in terms of time before we can have a device in our hands that supports this API. it’s likely that it will take years before l2cap channels will be reliable and available to a significant share of the android users.