I'm writing a P2P communication app between Android and Windows devices, that relies on Bluetooth as the underline communication channel. I would like to check the version of the Bluetooth protocol being used for each session (i.e. 2.x, 4.0, 4.1, 4.2, etc), in order to make security decisions accordingly (2.x is not very secure, 4.0 is more secure, 4.1 is most secure, etc).
How can that be achieved using API, on either Windows or Android? I'll have to check that for each session and session, because to my understanding, the Bluetooth version is determined as the minimum capability for both parties.
First, the Bluetooth version after 2.1 SSP, e.g. 2.1,3.0,4.x, is basically same secure(however if you are talking about LE security that's another story), you do not need judge the LMP version actually.
Unfortunately Android does not export the remote version to apps, the lower level(Bluedroid) "BTM_ReadRemoteVersion", this function can get remote LMP version.
Your understanding is partial right, "Bluetooth version is determined as the minimum capability for both parties.", both host and controller's capability was defined by their minimum versions.
I found a way to determine the version using Android logcat. During BT connection, I look for this line:
bt_btif_dm: remote version info [aa:bb:cc:dd:ee:ff]: 8, 2, 100
The first digit (8) is the LMP version, which corresponds to a Core Bluetooth version. (In this case, 8 means Bluetooth 4.2)
This does not solve my problem completely, because starting at Android JB an app cannot read the logcat anymore (except for its own logs). However, this is a good start... will update if I find anything else.
try this
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> Devices = mBluetoothAdapter.getBondedDevices();
List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getVersion());
Related
I want to transmit iBeacon data packet from android phone, with data flag.
Data Flag (0x01) is Bluetooth GAP specification that represents beacon's capability.
My situation:
Currently, I'm trying to advertise using BluetoothLeAdvertiser. But it doesn't works as I thought. I found that, I can only advertise "Manufacturer specific data".
BluetoothManager manager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
mBluetoothAdapter = manager.getAdapter();
mBluetoothLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
// Settings here
mBluetoothLeAdvertiser.startAdvertising(settings, getAdvertiseData(), mAdvertiseCallback);
My current result:
What I want:
Common iBeacon data packet(Image below) has data flag, Type 0x01. And I want to add this flag to my iBeacon advertise packet.
That means, I want add Raw data "0x020106" to head part of the packet.
How can I archive this?
Etc:
I have already read about question below, but it doesn't help for my problem.
Can an Android device act as an iBeacon?
Also, I already have read that android ble api doesn't support Data flag.
But the comment was in 2015, is there any hopeful changes now?
https://github.com/AltBeacon/android-beacon-library/issues/141
Unfortunately, this is not currently allowed by the Android BLE APIs, so the library cannot this.
Any help will be appreciated. Thank you.
Unfortunately, Android's Java BLE APIs expose no way of doing this. I researched this topic to answer the Android Beacon Library Issue you referenced. The Java APIs only let you advertise either service data or manufacturer data. They are simply not flexible enough to let you specify any other advertising PDUs. This has not changed as of May 2016.
You might be able to do what you want by dropping down to a lower level and talking to C BlueDroid APIs. But doing this would require a rooted device and perhaps installing a custom Android OS image to give you access.
We are using DiscoveredPrinterBluetooth to keep discovered printer, ZebraPrinterConnection and ZebraPrinter to send data to printer. Everything is working ok on older android versions, but on let say 4.0 is not working, finds printer but keeps showing insert pin screen. Get error in log:
V/BluetoothSocket.cpp(5371): ...connect(96, RFCOMM) = 111 (errno 111)
As I see there is problem with newer versions, looking at
Bluetooth pairing without user confirmation
but I don't know how to solve it in my case? Any ideas? Thanks
The 2.0 version of the Zebra SDK has an implementation of insecure bluetooth connections.
Check out BluetoothConnectionInsecure in the new SDK. This could be used instead of BluetoothConnection if you want insecure BT connections...
I have a device which runs android 4.1.
But the device does not have a bluetooth, so I want to remove bluetooth related items from the 4.1 platform (like sharing menu, setting items which contain "bluetooth ").
but it seems a miscellaneous work ( settings, filesharing , ).
Is there any method that can tell the platform that the current devices don't have a bluetooth only by config some files???
in Android 4.1 Settings.java (packages/apps/settings/) the code
// Remove Bluetooth Settings if Bluetooth service is not available.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
target.remove(header);
}
is used to judge if the devices support Bluetooth service.
the configing files are under systemtem/etc/permissions/xxxx.xml which are copied from /framework/base/data/etc/xxx.xml
PackageManager.FEATURE_BLUETOOTH = "android.hardware.wifi"
PackageManager.FEATURE_BLUETOOTH = "android.hardware.bluetooth"
Since it only provides a method to flag whether the devices support Bluetooth service, the View items that contain Bluetooth should be removed separately.
im testing the new technology wifi direct and im having some issues using
the wifi direct demo from the samples that come with the android-sdk.
So, I have two devices A and B, both with android 4.0.3.
First, from device A, I send a file to B. Nothing wrong here, B
receives the file.
Then A disconnects from B.
Now, from device B I try to send a file to A.
But the device that receives the file is B, instead of A.
To fix, i need to turn off and on both devices...
Also, sometimes when i click disconnect and try to
connect again, connection fails and i have to disable and
enable wifi direct...
Anyone else experiencing this?
Is it because the new technology is not mature yet or maybe
something wrong with my build/driver/etc or maybe this demoapp
doesnt support two-way sharing.
Any ideas and/or explanations would be apreciated.
When providing a WifiP2pConfig instance to the connect() function, you can set the groupOwnerIntent property of this configuration object as follows:
WifiP2pConfig config = new WifiP2pConfig();
config.deviceAddress = "..."; // insert ip here
config.groupOwnerIntent = 0;
config.wps.setup = WpsInfo.PBC;
manager.connect(..., config, ...);
From the android reference:
This (the groupOwnerIntent) is an integer value between 0 and 15 where
0 indicates the least inclination to be a group owner and 15 indicates
the highest inclination to be a group owner.
Furthermore, the demo probably repeatedly sends the file to the same device because there is always made a socket connection to the ip-address obtained from:
WifiP2pInfo.groupOwnerAddress
If you would like to support bidirectional communication, the first step in setting this up would be sending the ip-address of the non group owner to the group owner.
As far as the disconnect/reconnect problem goes, I seem to have the same inconsistencies with Android 4.0.2 devices.
I have been trying for a while to transfer files between two devices using wifi direct. I have use the Android SDK WifiDirectDemo as base. My experience:
GO address is always the same (at least in Samsung Nexus), but this is not really a problem, because you can use this to know who is the server (or client).
Another strange thing was that MAC address of devices were different when you got it from Android WifiManager and when you read it from "/proc/net/arp" file.
At the end I did it, and you can see the code here.
I hope it helps you!
I have been struggling with the same problem lately. I suppose this is an OS issue. To give you a brief background, I have installed Wi-Fi Direct application to both devices with different OS versions, one with OS 4.0.1 and one with OS 4.0.2. The connection fails from time to time when I disconnect and reconnect the devices. It goes same while searching for devices too. But the thing is, this only happens on the device with OS 4.0.2. Other device does not crash or disconnect.
While searching for that problem, I have found the links below. People discussed about that and they share the same idea. Apparently this is an OS 4.0.2 issue. I am not sure if it is the same for OS 4.0.3 but there is no problem with the previous version OS 4.0.1 for sure.
Here are the links:
http://code.google.com/p/android/issues/detail?id=24402
http://osdir.com/ml/android-platform/2012-01/msg00226.html
Two question on Bluetooth development on Android:
Is there a way to enable Bluetooth to be always on (I might have a long device discovery phase in my application) in Android? As far as I can see the default value is a count down from 120s.
Does it exist any open source Bluetooth API implementations?
Bluetooth implementation is now available in the Android 2.0 API.
See this and this.
Enabling Bluetooth to be always on, may not be a good decision, if your only concern is long discovery delay ("battery life"-wise).
As for third-party Bluetooth APIs, the only thing that I've heard of is iAnywhere Blue SDK (from Sybase, not free, only evaluation version available), which covers some of the features, that will be supported in the future from the system/bluetooth and bluez packages.
According to the Android's Bluetooth roadmap, most of the long waited things like Java API, Bluetooth 2.1 + EDR will be implemented, at one point in the future.
Good luck with your project.
On 2.3.6 I can keep the device always visible by putting the delay 0:
Intent di = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
di.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
The Bluez stack on Linux is an open source implementation. It's also available on Windows but the API is much more complete on Linux.
When you say, 'enable Bluetooth to always be on' do you mean, always trying to discover other devices?
Most bluetooth chips have a deep sleep mode, where the chip is mostly down and just comes up a to check for activity on any established links. It will only wake up to full power when you want it to do something (discovery, make a connection) or there is activity on an existing link.
Yeah, it uses more battery power than if the Bluetooth were totally off but it's not a total vampire.
private void ensureDiscoverable() {
if(D) Log.d(TAG, "ensure discoverable");
if (mBluetoothAdapter.getScanMode() !=
BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
}
http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#ACTION_REQUEST_DISCOVERABLE
BlueCove is an open-source bluetooth implementation for Java.
It works on a lot of different machines and if correct there is a Android compatible version lurking around somewhere.