Quick question. I can't seem to find this in the Android docs, so I don't think it is possible, but is it possible to have an Android 4.3 device (in my case, a Nexus 4) behave as a Bluetooth peripheral? I know iOS supports both peripheral and central, but it seems like Android only supports central.
I'd like to connect an Android device to a Mac using Bluetooth LE, but since OS X doesn't support peripheral mode and it looks like Android doesn't either, I might have to go with Bluetooth 2 or another communication method.
Unfortunately there is no way for Android devices to act as a peripheral. He can creates GATT servers, services and charachteristics but there is no way to make the advertising.
Doc: http://developer.android.com/guide/topics/connectivity/bluetooth-le.html
The phone supports the central role;
I'm waiting for this feature too, but it seems we have to wait for next Android releases.
Yeah, Android 4.3 does not support peripheral mode. I started a feature request on the Android Open Source Project website. If you also want to see this feature, add a comment or star the post. I think they will get around to it eventually, but it is good to let them know that this is a feature that developers are looking for.
https://code.google.com/p/android/issues/detail?can=2&q=59693&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&id=59693
issue: 59693
In API level 4, 4.1,4.2,4.3 its not possible.
Android lollipop API version 5.0.X sdk supports peripheral mode in BLE however this feature is chipset dependent (Phones).
android phones with Broadcom Bluetooth solution already supports it
If you have a Nexus 5 you can install Android L there and try it, I just did it few months ago, Android L has support to act as a peripheral.
Related
Has anybody used Samsung's Bluetooth LE APIs to make a Samsung Android device advertise as an iBeacon? This should be possible, but I do not have access to a device to try it.
If anybody has used it to make a Samsung Android device advertise as any other Bluetooth LE peripheral, I would like to know that, too.
EDIT: This is now possible on Android L. See here.
EDIT: this answer is about older Samsung phones with Android 4.2. Samsung devices with Android 5.0+ can advertise beacons successfully.
Unfortunately, #reTs and #duncan-c are right (+1 for each of them). The Samsung BLE SDK cannot send out real BLE advertisements as is required for iBeacons.
I was holding out hope because their documentation says "allowing applications to create and advertise Bluetooth smart services and characteristics". I wrote an app to prove whether this actually worked, and learned that their documentation is simply misleading. The Samsung BLE SDK will not make Samsung devices transmit advertisements over the radio.
See full details in this blog post.
http://developer.samsung.com/ble
You can view the official "Samsung BLE SDK Guide and Hints" on the above link.
On page 12, point 10, it said :
"The current version of the SDK supports only the GATT central role. Peripheral roles may
be supported in future releases."
I'm told that with the current firmware it's not possible. (I'm not an Android developer so I haven't confirmed this first-hand.)
Till Android 4.3, an Android device with Bluetooth Low Energy support could only act as a central device. As is given in the Android 4.3 Bluetooth LE docs:
Android 4.3 (API Level 18) introduces built-in platform support for Bluetooth Low Energy in the central role and provides APIs that apps can use to discover devices, query for services, and read/write characteristics.
With the introduction of Android 4.4 KitKat, can it also behave as a peripheral device now? I couldn't find any documentation of that. If not, then do we have to wait for Android 4.5 for getting the BTLE peripheral mode on Android device? Or is there any alternative way in which an Android device can be made to act as a peripheral device?
Not in this version but there is evidence that it is coming soon.
If you look in BluetoothGatt.java in the android-19 sources there are new methods listen and setAdvData that weren't there in android-18.
However these are not documented as I don't think native support is complete yet. The last check in on AOSP for peripheral mode was titled "LE: Add peripheral role support (2/4)". Also, setAdvData and listen have this code:
if (mContext == null || !mContext.getResources().getBoolean(com.android.internal.R.bool.config_bluetooth_le_peripheral_mode_supported))
{
throw new UnsupportedOperationException("BluetoothGatt#listen is blocked");
}
Looking in android/platform_frameworks_base/blob/master/core/res/res/values/config.xml from the Android sources you can see this is currently disabled:
<!-- Boolean indicating if current platform supports BLE peripheral mode -->
<bool name="config_bluetooth_le_peripheral_mode_supported">false</bool>
Thanks everyone for the answers. Just to update, as of June 2014, it is offered in the Android L Developer preview. Hope to see it in the Android L official release. From their blog New in Android: L Developer Preview and Google Play Services 5.0:
The L Developer Preview, lets you explore many of the new features and capabilities of the next version of Android, and offers everything you need to get started developing and testing on the new platform. Here are a few of the highlights for developers:
BLE Peripheral Mode — Android devices can now function in Bluetooth Low Energy (BLE) peripheral mode. Apps can use this capability to broadcast their presence to nearby devices — for example, you can now build apps that let a device to function as a pedometer or health monitor and transmit data to another BLE device.
Update:
The bad news is that BLE Peripheral mode will only work on the newer Android devices (as per the date), viz Nexus 6 and Nexus 9. It won't work on Nexus 4/ Nexus 5/nexus 7/ nexus 10 even if you update it to Android 5.0. You can read the comment by one of the Android Project manager on BLE advertise mode not working ticket. He says:
We introduced BLE peripheral mode in Android 5.0 Lollipop. Nexus 6 and Nexus 9 are the first two production Nexus devices that support BLE peripheral mode. Due to hardware chipset dependency, older Nexus devices (4/5/7) will not have access to the feature on Lollipop.
http://developer.android.com/sdk/api_diff/19/changes.html
By looking at the full api difference, the answer in short : NO
==============
To add peripheral role support now you have to get your hands dirty to customize the Bluedroid stack in the OS level, or try your luck on XDA developers to see if anyone has done this before. I am not sure the current Android phone support peripheral role at hardware level,though .
Does anyone know the best way to detect Bluetooth LE advertisements on a Android device? I need to only retrieve the service UUID and RSSI value from the advertisement packet, I don't need to connect with the device--If this makes a difference. Do I need to use one of the vendor specific Bluetooth API's like Broadcom for a device that contains a Broadcom bluetooth module?
As of Android version 4.2, the Broadcom stack has been integrated into Android and will work out of the box. Prior to that you needed to run another stack to give BLE access, as stock Android had no APIs.
As of SDK 18 Android now has APIs for this. However, in my testing they do not work properly on the Nexus 4 with 4.3.
See documentation here:
http://developer.android.com/guide/topics/connectivity/bluetooth-le.html
I am involved in a Android Project that connects the sensor using Bluetooth 4.0. AFAIK android didn't support Bluetooth 4.0. I tried with my laptop bluetooth 4.0. I tried with Broadcom using this. Later i came to know my Laptop Bluetooth 4.0 is Atheros Bluetooth 4.0 and later i searched for Atheros Bluetooth 4.0 API using android mobiles and tablets. I saw Qualcomm having Bluetooth 4.0 tablet. I want to know, is Atheros giving API for Bluetooth 4.0 for Android SDK.
Finally, long way of search, i found that up to today(23/12/12), Atheros not giving Bluetooth API for developers. But they are providing other API's for Audio, Camera, Device Info and Sensor(mobile shake). So, can't try on laptop also. Dgel comment and link helped me a lot and made me, come to the conclusion.
Android Bluetooth (and other) API's are not specific to the hardware (or software stack).
They are generic and fairly high-level, and Yes they include Bluetooth 4.0.
The actually support for BT 4 depends on the device. Recent Nexus devices support BT4 (both in hardware and in software) as long as they have the Android 4.2 update.
If you root your device you can get to the 'raw' vendor API's, but I don't know what that looks like for BT4, or wheteher any of that is published. In most cases that is Broadcom based, not Atheros.
EDIT:
I just saw this:
http://code.google.com/p/broadcom-ble/
I'm not familiar with this, but I suspect that it was just a stop gap measure before BT4 was added to the official Android API in 4.1.
I'm trying to find way to work with Bluetooth 4.0 (AKA Bluetooth Smart) devices using modern Android smartphones, namely - HTC One V.
As I understood, there is some issues using GATT profile even in Android 4.0 with Bluetooth 4.0 hardware because of API limitations.
I saw Motorola released it's own API for BT LE, but not sure it will work for other vendors.
My goal is to get universal support for all smartphones with appropriate hardware.
Any suggestion for solution are highly appreciated.
Alexey
PS: Yes, I saw Android API for HDP, but it seems to be used only with 'classic' Bluetooth devices (not low energy ones, as BT LE does).
Unfortunately there are no Android native GATT APIs simply because Android currently does not support Bluetooth Low Energy at all. This may change in upcoming Android releases, but today manufacturers instead integrate 3rd party Bluetooth stacks with Low Energy support from vendors like Qualcomm, Broadcom or CSR. Those come with their own set of APIs, obviously limiting compatibility to the set of phones using that particular vendor's stack.
The good news is that on other platforms like iOS or Windows 8 there are native GATT BLE APIs, and those are well supported. For Android, we will have to wait until Google decides to integrate the Linux/BlueZ work that has been done on BLE with Android.
After some research I can only say this:
Motorola has sided with Broadcom to develop a proprietary API. It would seem it is extremely limited since it states there's support for existing profiles only. Check it out here.
Samsung fails to provide any information regarding its BLE API, which I can verify exists and is called samsung.bluetoothle. I actually decompiled some apps from Google Play that use the SGSIII's BLE capabilities and found a couple of methods that do not exist in Android's native BT API, and they're names clearly state they're BLE related. I've tried using them through java reflection and am currently working out the possibility of developing a library. But tests I've run so far have had shakey results at best. There is also a thread on Samsung's developer forum, I would suggest making some pressure here if you're interested.
Google has made almost no remarks in this aspect. There's a thread regarding this issues in the Galaxy Nexus, which you should star, with a lot of people complaining. The closest thing to an answer from Google can be found here.
[UPDATE]
Samsung has also modified a couple of Android's classes, more especifically:
BluetoothAdapter
BluetoothDevice
[UPDATE]
Since I've put this issue aside for a while due to lack of support from both Google and Samsung I'll post what I've learned so far:
BluetoothAdapter new methods:
public boolean android.bluetooth.BluetoothAdapter.leTestEnd()
public boolean android.bluetooth.BluetoothAdapter.setAvStreaming(boolean)
public boolean android.bluetooth.BluetoothAdapter.setScanLE(boolean)
public void android.bluetooth.BluetoothAdapter.setScoPathChange(int)
public boolean android.bluetooth.BluetoothAdapter.startLeDiscovery()
To use them do the following:
BluetoothAdapter ba = new BluetoothAdapter();
Method starteLeDiscoveryMethod = null;
starteLeDiscoveryMethod = ba.class.getMethod("startLeDiscovery");
starteLeDiscoveryMethod.invoke(ba);
NOTE: This method in particular works somewhat like the regular startDiscovery() method but, at least for me, it discovers the BLE device 2 out of 5 times.
And remember, this is only for the SGSIII. I haven't gotten around to extracting the new methods in BluetoothDevice but when I do, I'll post them here.
SDK 18 has support for it now. Docs are here:
http://developer.android.com/guide/topics/connectivity/bluetooth-le.html
Testing on my Nexus 4 is crashing the bluetooth stack.
HTC has had BLE support since last year with HTC One X+, Droid DNA and of course the HTC One. Initially the HTC BLE API was upon request but it's now been freely downloadable at http://htcdev.com.
Yes the new standard Android BLE API from Google in Android API Level 18 is coming very soon (see preview from IO video) - but you can wrap third party APIs (HTC, Samsung, etc) in a compatible way to support the new standard API as all the APIs are quite similar in their support of the GATT profile (similar to IOS).
BluetoothGatt api available in andorid
https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html
As discovered, 4.3 has support for BLE, but it so broken, especially on Nexus devices.
At my opinion, it's not ready for production.