Bluetooth support in Android on Beaglebone - android

I am cutting my teeth on Android this week and I have a Beaglebone Black running an Android JB 4.2.2, linux kernel 3.2 image from TI with a Broadcomm BCM20702 usb bluetooth dongle attached.
The dongle works alright in Angstrom but I am sufficiently neophyte as to not recognise if the support is there in Jelly bean.
I begun testing with the following code:
private BluetoothAdapter BA;
BA = BluetoothAdapter.getDefaultAdapter();
Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
I get my BA, i get my turnOn intent but when I start the intent I get the allow permissions dialogs then the "Turning Bluetooth on..." modal indication which never clears.
The application threads are all running in the debugger but the UI looses focus and is unresponsive.
What can I do to debug the situation ?
How do I determine whether the dongle really is supported in this kernel or enable support if not ?
What provisions are in the Android UI for bluetooth connection/setup (I haven't seen any which may indicate a current lack of support)?
How can I debug the hung dialog "Turning Bluetooth on..." ?
Cheers much,
Chris

Related

IOIO open accessory connection upon non-activity base

I did a small android program what works well if usb debugging is on. This program will be as a lib for B4A. I would like if it do work without usb debugging for higher version of android, i.e > 4.2, but I have an exactly 4.2 phone where I can test it and when I switch off the debugging mode the program can't connect. In the same phone the official Helloioio program can work in open accessory mode (as mine should be too), so the problem in this case surely not device dependant. What is the correct connection sequence for android open accessory connection for IOIO?
This is the connection part of my code:
BA.Log("IOIOConnectionRegistry.addBootstraps");
IOIOConnectionRegistry.addBootstraps(new String[]{
"ioio.lib.android.accessory.AccessoryConnectionBootstrap",
"ioio.lib.impl.SocketIOIOConnectionBootstrap",
"ioio.lib.android.device.DeviceConnectionBootstrap",
"ioio.lib.android.bluetooth.BluetoothIOIOConnectionBootstrap"
});
BA.Log("IOIOFactory.create");
m_ioio_thread = IOIOFactory.create();
BA.Log("waitForConnect");
SystemClock.sleep(50L);
m_ioio_thread.waitForConnect();
BA.Log("Connected");
Thanks in advance!

Android Open Accessory Protocol using javax.usb

I'm working on getting any existing device communicating with Android devices. The device uses javax.usb (which is built on top of libusb) for usb communication and I am attempting to implement the Android Open Accessory Protocol using it. The device currently recognizes the android device and registers the android device with my application. However when I try to:
Attempt to Start in Accessory Mode - Send a 51 control request ("Get Protocol") to figure out if the device supports the Android accessory protocol.
I get a UsbStallException and my app dies. I know very little when it comes to usb from what I have been reading this should work.
Here's the relevant code:
byte req = (byte) (0x80 | 0x40);
UsbControlIrp irp = usbDev.createUsbControlIrp(req, (byte)51, (short)0, (short)0);
usbDev.syncSubmit(irp);
Any insights as to what I'm doing wrong would be appreciated.
PS: the device I'm running this on uses a 1.4 JVM so any solutions will be constrained by that

Bluetooth is not detected in my system but is in phone

I am working on a project related to Bluetooth. I wrote this sample code to detect Bluetooth in a device.
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
if(bluetooth!=null)
{
Toast.makeText(getApplicationContext(), "gfvhfh", Toast.LENGTH_LONG).show();
}
This code is working perfectly in my phone and displaying the text in toast, but in my system it's not showing anything. I am using a external Bluetooth adapter for my system.
I guess that by system you mean emulator, in that case it is 100% normal.
You can't use Bluetooth on the emulator as said here.
Please check before asking a question that it hasn't been asked before!

Android Application Bluetooth visibility duration

Is there a way to let my application be discoverable for a time the app is running? I tried to do this with
Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
startActivityForResult(discoverableIntent, DISC_DURATION);
as shown on Android Developers, but the Duration of 0 doesn't work so the default value 120 is set. Is there a way to set it as visible all the time?
there is no mean for keep Bluetooth discoverable all time.
At the time when you want to find some new devices or other devices can find your device you have to make it discoverable.
After that your device will interchange a shared MAC id and will make a paired.
Performing device discovery is a heavy procedure for the Bluetooth adapter and will consume a lot of its resources. Once you have found a device to connect, be certain that you always stop discovery with cancelDiscovery() before attempting a connection. Also, if you already hold a connection with a device, then performing discovery can significantly reduce the bandwidth available for the connection, so you should not perform discovery while connected.
for more info see this
http://developer.android.com/guide/topics/wireless/bluetooth.html#DiscoveringDevices
There is no way for you to set bluetooth to be continuously discoverable on any 2.* version of Android; see this bug report. It seems like the limitation has been removed in 3.* versions, but I haven't seen any confirmation of this.
I come to the conclusion on three devices I have.
ANDROID v 4.3 and higher : EXTRA_DISCOVERABLE_DURATION 0 works no limit
ANDROIND v 4.1 : EXTRA_DISCOVERABLE_DURATION 0 is max 1 hour. Have to change manually to no limit in parameters.

Android - How to enable Bluetooth to be always on?

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.

Categories

Resources