We are working on a project that needs to support a range of devices.
For devices above api level 18 there must be Bluetooth LE support, making use of the BluetoothAdaptor class.
Now comes the problem, since it's imported from a cordova plugin our app crashes on boot on low api devices.
So now we are looking for a way to use the class, without loading it beforehand.
So we check for api level, if it is supported we want to load the class.
Is there a way? We heard about dynamic class loading, is this the way?
use null safe for this according to me. for device older(<18) class BLE and else BluetoothAdaptor .
Bluetooth = Bluetooth! BLE ? BluetoothAdaptor;
Related
I have an old Android device using Gingerbread which is bluetooth low energy capable.
However when I try to build a BTLE app Android Studio complains saying that minimun SDK is 18 and I have 10.
I tried to avoid those problems using SuppressLint and I can compile the application but dalvik complains about linking the class.
Link of class 'Lcom/package/class;' failed
Is there any way to force dalvik to link my class even if I have an older Android device or to modify bluetooth low energy api so that it doesnt complain?
Any idea where does Android studio gets the information to know that BTLE api is only available from API > 18?
Thanks
Any idea where does Android studio gets the information to know that BTLE api is only available from API > 18?
Of course Android studio got the information from the SDK.
Is there any way to force dalvik to link my class even if I have an
older Android device or to modify bluetooth low energy api so that it
doesnt complain?
Simply no way to force it working. The api just does not exist before API level 18.
If by "modify bluetooth low energy api" you mean you will build your own version of Gingerbread with BLE support, you will have a extremely slim (or non-existent) chance to get it working. However please keep in mind that having a chip that supports BLE does not mean the device can use BLE.
Im working on a simple Android application and need it to have the ability to connect to a Bluetooth low energy device. Im relatively new to Android development and was wondering if there were any frameworks or SDKs that I had to download to make this possible.
You should look in to Bluetooth Studio
Nope, you should not need anything special to work with Bluetooth low energy on Android at long as you are targeting a platform that is API 18 or higher. An excellent place to start as mentioned in the comment above is the Developer Documentation. The other place I would look at for an example are the samples provided by Google. The BLE one can be found here. Be warned though that devices with API 18 devices do support BLE, they had a lot of bugs, and you might be better of just supporting a minimum level of 19 (KitKat).
I need some guidance on a project im currently working on - I work on a project to communicate with a BLE device s.t. the device is connected to an android phone and transmits some data once in a while. I saw some lectures on BLE communication with android devices and read some information on the android 4.3 bluetooth API but there are some things I didnt got yet
In case I want my app to be compitable backward (up to 2.3) is that possible? did they (Google) include the new features on the support package?
Where can I find some good code example of using the android as a client?
When communicating with an android device I need the charestirestic of the bluetooth device to have UUID, do I generate some UUID's on the run? (and in that case how) or do I hard-code them on the app? (since on that case two people using this app and close to each other basically can read each other's signal, don't they?)
In case I want my app to be compitable backward (up to 2.3) is that possible? did they (google) include the new features on the support package?
Bluetooth low energy needs to be supported by the HW and there are only a handful of devices with the necessary Bluetooth radio running an older version of Android. For sure no device running 2.3 will be able to run BLE.
Where can I find some good code example of using the android as a client?
The examples provided on developer.android.com is actually quite good
When communicating with an android device I need the charestirestic of the bluetooth device to have UUID, do I generate some UUID's on the run?
Bluetooth Special Interest Group has already created a bunch of assigned numbers. These have a well defined meaning across all BLE devices and services. Then businesses can apply for a range of UUID's that they can use to defined there own services.
On top of that there are some free ranges where everyone can define and use UUID's. These will not be well defined across devices, meaning other applications will not understand the UUID's you've defined.
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.
Up to now I was only developing in J2ME and would like to know about the differences compared to Android.
The situation for a java enabled phone is that it might, for example, has a built-in camera, but the manufacturer didn't implemented the Java API for camera capabilities. Which means you can't use that API. It is even possible that only parts of an API were implemented.
Now, what about Android? For what I know, when a device has Android Platform 2.2 it supports every API Level up to Level 8. And I would guess, that if the built in camera doesn't have a flash then you can't use the Android API call to change the flash mode. Is that right?
Now let's assume that the device has a built in flash enabled camera. Can a developer be sure that the function for changing the flash mode can be used, or is it possible that the manufacturer didn't implemented that specific function even though it is part of the supported API Level which the device was advertised for?
And I would guess, that if the built in camera doesn't have a flash then you can't use the Android API call to change the flash mode. Is that right?
So long as you set it to a valid value, you can always use the API. However, in your case, there is probably only one valid value (i.e., no flash).
Now let's assume that the device has a built in flash enabled camera. Can a developer be sure that the function for changing the flash mode can be used, or is it possible that the manufacturer didn't implemented that specific function even though it is part of the supported API Level which the device was advertised for?
Android devices that do not have the Android Market have no guarantees whatsoever regarding their compatibility with third-party apps.
Android devices that do have the Android Market must pass a compatibility test suite. Whether or not that test suite has a specific test for a specific API can only be determined by looking at the test suite code.
So, it depends on how you define "sure". Developers usually don't have to worry about it, but device firmware bugs do happen.