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 answers
Related Questions in ANDROID
- Creating global Class holder
- Flutter + Dart: Editing name of a tab shows up a black screen
- android-pdf-viewer Received status code 401 from server: Unauthorized
- Sdk 34 WRITE_EXTERNAL_STORAGE not working
- ussd reader in Recket Native module
- Incorrect display of LinearGradientBrush in IOS
- The Binary Version Of its metadata is 1.8.0, expected Version is 1.6.0 build error
- I can't make TextInput to auto expand properly in Android
- Creating multiple instances of a class with different initializing values in Flutter
- How to create a lottie animation
- making android analyze with coverity sast tool
- Flutter plugin development android src not opening after opening example
- I initialize my ViewModel in the Activity with several fragments as tabs, but the fragments(tabs) return null for the updated livedata
- Node.js Server + Socket.IO + Android Mobile Applicatoin XHR Polling Error...?
- How I can use the shared preferences class?
Related Questions in BLUETOOTH
- React native - how can i listen callBack function
- java android: how to send data on Bluetooth between android and computer
- Pair bluetooth device to Android 12 phone by selecting my own pin
- Bluetooth virtual sniffer for windows
- PyBluez connection problems
- How to set value the descriptor of iOS BLE in Objective-C?
- python script using bluetooth running on windows 11 vs raspberry pi4
- Mobile printing PT200 tru Bluetooth opened in web app
- PlatformException(connect_errd or timeout)
- Bluetooth Driver file corrupt or replaced
- Bluetooth driver Failed and unable to install bluetooth driver for jammy ubuntu
- strange Flutter bug on turning on/off bluetooth permission using IOS device
- Call requires permission which may be rejected by user code should explicitly check to see if permission is available
- Error during getting android Bluetooth device RSSI from Windows 10 using BlueCove library
- Error in Bluetooth specification? Heading field of Location and Speed
Related Questions in BLUETOOTH-LOWENERGY
- How to receive Bluetooth value in Android app
- provision failed and giving null pointer exception in android using ESP provisioning Library
- Need the decoded data while from server esp32 send and Receiving in react native cli
- python script using bluetooth running on windows 11 vs raspberry pi4
- How to make sure only one client connect to the BLE server on ESP32?
- Samsung SM-A546E Bluetooth in background odd behaviour
- Android OnCharacteristicChanged - Continuous stream of bytes from Bluetooth Stethoscope
- ESP32 BLE Arduino And getting a compile error of 'ringbuf_type_t' has not been declared
- (corebluetooth didUpdateValueFor) data is not being sent properly between my peripheral arduino 33 nano and iOS app
- Constructing a script using a 3rd party library
- BLE SMP packets sniffing using scapy python
- Error in Bluetooth specification? Heading field of Location and Speed
- How to understand the Sensor Setting Property ID in the SIG Mesh model
- Problem with mapping of BLE 5.1 ATT protocol stack with winsock & winsock2 arcitechture
- Plot ecg graph in flutter
Related Questions in L2CAP
- bluetoothLeScaner.startScan(scanCallback) isnt returning null
- Encryption using L2CAP Connections over channels
- btsnooz_hci.log truncated packet?
- iOS Swift Facing issue on data transfer over CBL2CAPChannel
- What parameters should I use for L2CAP connection request in BLE data transfer between a Bluetooth 5.0 and 4.1 device?
- L2CAP communication in background mode
- Optimize Bluetooth LE L2CAP throughput between Linux running bluer l2cat and iOS
- When did the L2CAP SMP channel create?
- iOS L2CAP/GATT- throughput
- CBL2CAPChannel not responsive while app is backgrounded
- NSStream (BLE L2CAP) on background thread
- BluetoothSocket.connect() Android 12 Permission issue on certain devices
- Concurrent L2CAP and/or GATT Connections between 2 Devices
- Why are there two different socket options (RFCOMM and L2CAP) in BlueZ?
- can't send data through l2cap raw socket for local controller - [Errno 107] Transport endpoint is not connected
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?
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)
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
BluetoothSocketclass 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:
createL2capSocketmethod in android 8 (source)createL2capCoCSocketmethod in android 9 (source)createL2capChannelin the master branch of the android project (future release I guess?) (source)But in each released version this code is marked with the
@hideannotation, 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.