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
- Delay in loading Html Page(WebView) from assets folder in real android device
- MPAndroidChart method setWordWrapEnabled() not found
- Designing a 'new post' android activity
- Android :EditText inside ListView always update first item in the listview
- Android: Transferring Data via ContentIntent
- Wrong xml being inflated android
- AsyncTask Class
- Unable to receive extras in Android Intent
- Website zoomed out on Android default browser
- Square FloatingActionButton with Android Design Library
- Google Maps API Re-size
- Push toolbar content below statusbar
- Android FragmentPagerAdapter Circular listview
- Layout not shifting up when keyboard is open
- auDIO_OUTPUT_FLAG_FAST denied by client can't connect to localhost
Related Questions in BLUETOOTH
- Bluetooth connection to Sphero is lost when smartphone "goes to sleep"
- MFi Program by Apple
- Android Wear Device as iBeacon
- android - How to get a iBecon detection state when I kill app from Background?
- IOException: broken pipe when sending file from android device to PC via Bluetooth
- How deploy an large number iBeacons
- Send a Android BLE GATT Notification
- burst notifications with Bluetooth Low Energy on Android
- Is there a way to change bluetooth module's baud rate via Bluetooth connection with Android device?
- NFC Bluetooth handover - WITHOUT user confirmation
- Is it possible to create an app that when installed the user can easily turn Bluetooth/NFC ON and OFF by double clicking the Home button?
- Difference between attributes and services in BLE
- Global name 'bluetooth' is not defined
- iOS Bluetooth list of devices already connected?
- Bluetooth discovery not starting on first click
Related Questions in BLUETOOTH-LOWENERGY
- How to read a characteristic (e.g. in WICED Smart example "speed_test")
- Android Wear Device as iBeacon
- How to get MAC Address of beacon when ranging and monitoring in iOS
- android - How to get a iBecon detection state when I kill app from Background?
- How to use core bluetooth framework to connect Headsets/handsfree?
- Android : auto connect to heartrate sensor ble
- bluetoothGatt writeCharacteristic returns false
- Android's BLE Service Discovery (BluetoothGatt#discoverServices()) and Low Energy vs BR/EDR
- How deploy an large number iBeacons
- Send a Android BLE GATT Notification
- burst notifications with Bluetooth Low Energy on Android
- How to share files with all other devices from my iOS device through application?
- Is it possible to create an app that when installed the user can easily turn Bluetooth/NFC ON and OFF by double clicking the Home button?
- Difference between attributes and services in BLE
- How do I use Meteor and a Cordova BLE plugin to connect to a BLE device
Related Questions in L2CAP
- How can I establish an AVRCP connection from Windows 7 (controller) to phone (target) using L2CAP on Widcomm SDK?
- Bluetooth protocol (RFCOMM, L2CAP and ACL)
- Android BT Stack in Kit Kat
- How to make a testing bluetooth connection from a desktop PC to an android device
- Bluez L2CAP CoC to Android / iOS Credit based flow failing
- Multiple L2CAP channels on iOS (rdar://46227689)
- Connecting with Bluetooth L2Cap to HID Device
- Android BLE Connection time interval
- iOS L2CAP/GATT- throughput
- When did the L2CAP SMP channel create?
- Optimize Bluetooth LE L2CAP throughput between Linux running bluer l2cat and iOS
- about bluetooth spp retransmission
- BluetoothSocket.connect() Android 12 Permission issue on certain devices
- CBL2CAPChannel not responsive while app is backgrounded
- How can I instantiate a L2Cap socket in Android?
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 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
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.