http://developer.android.com/resources/samples/BluetoothChat/index.html
As you know, the emulator does not have bluetooth support. My question is: is there any workaround to test the bluetooth chat from the sample?
The documentation states there is no Bluetooth support for the emulator. And you really should just test with devices if you have access to them.
I have never tried this, but I have read over before just finding a spare device. So if you are really stuck with just the emulator you can give this a shot. It's not a guarantee but it's something to look into.
https://github.com/cheng81/Android-Bluetooth-Simulator
Last I checked it supports:
switch on/off the "radio"
discovery devices (only other android emulators)
creating bluetooth services
connecting to bluetooth
services
You probably have to test/debug with real devices - IMHO there's no way to get bluetooth working on the emulator, not even a workaround
Related
I am Deciding to create an android app using java in android studio to connect, send and receive data using ESP32 with all the available connection methods that is Bluetooth classic, Bluetooth low energy and wifi . Can anyone share any resources or Source codes?
did try some android apps but either not working or slow
Please take a look at the official Android Development Guide. You will find many topics covered, especially interesting for you will be
the guide to Bluetooth Classic
the guide to Bluetooth Low Energy
the guide to Wi-Fi
The guides offer you a good start on these topics. There are many more independent guides online, sometimes even providing a sample app
I want to write a Java app that scans for a specific BLE device. I decided to use TinyB library and start with testing some examples.
Unfortunately, these do not see my device (it does not show up in BluetoothManager.getDevices()) even though hcitool lescan shows it. Examples can detect my phone, so it looks like library works, but not for BLE devices.
How do I make it find the same devices hcitool does? Maybe I should use some other library?
I guess I'll be polling hcitool lescan and messaging my app whether device was found.
I use the following code for an Arduino Uno:
#include <SoftwareSerial.h>
SoftwareSerial device(2, 3);
void setup()
{
device.begin(9600);
}
void loop()
{
device.println("33,89,156,203,978,0,0;");
}
No specific device to send to is set.
If I want to receive the data on my laptop (running Ubuntu 14.04) I simply call:
sudo rfcomm bind rfcomm0 [MAC ADDRESS] 1
and
screen /dev/rfcomm0
in another terminal instance and it works.
How can I achieve the same behaviour with an Android app?
The following example code specifies a device. I cannot find any other code. Additionally it only works when I listen on the laptop for an incoming connection like this:
sudo rfcomm listen rfcomm0 [MAC ADDRESS]
I want my Android app to work exactly like the Arduino example. How can I achieve that?
Unfortunately Android doesn't appear to have low level Classic Bluetooth APIs which would allow you to do broadcast type behavior. This makes some sense as Android is intended to go into a power limited devices and active radios use energy. If you are required to use Classic Bluetooth (3.x) and Android to handle sending or receiving broadcast type behavior you'll probably need to write a custom ROM.
However there is specification called Bluetooth Low Energy (4.x) allows for less energy consumption but slower/less data throughput. Specifically the Advertising mode. Android devices which are scanning can pick up the short advertised data packet broadcasted by a device called a 'beacon'. Protocols which use this mode are Apple's iBeacon and Google's Eddystone.
Look here for sample apps involving Advertisements:
https://github.com/googlesamples/android-BluetoothAdvertisements
https://github.com/devunwired/accessory-samples/blob/master/bluetoothadvertiser
Also note that Android devices don't always support BLE Peripheral Mode which is what you will need for your Android device to act like beacon.
Related link:
Can an Android device act as an iBeacon?
And a nice list of what devices have been tested:
http://altbeacon.github.io/android-beacon-library/beacon-transmitter-devices.html
So in your case you should still be able to use your Sony Xperia Z3 as a Scanner, but will have to buy/build a beacon for testing.
In a project I am currently working on, I am using a PIPO T9 tablet to run an app that uses the USB port to communicate with a transceiver. The reason I chose this tablet is because it has a usb port and a 5vDC power input (seemingly) allowing it to be powered while the USB port is in use. I found out later that only one can be used at a time.. So now I have been searching for a way to either:
Programattically force the tablet to disable USB host while the app is not being used. Hopefully allowing the tablet to switch to charging from the 5vDC line, or
Use an OTG Y cable to charge and get data from the USB port
So far I have tried the OTG Y cable method and it seems that this wont work with the tablet. When the tablet is off it has no trouble charging but as soon as its switched back on, charging stops. I have seen some similar questions on here and the recommendation was to use USB Accessory mode but I'm struggling to find out whether this will work with a tablet running 4.42 (NOTE: This tablet has been Rooted).
As always if anyone has any advice I would hugely, hugely appreciate it.
Thank you in advance :)
I am trying to develop an android app for managing HID devices.
Using UsbManager and getDeviceList() provided from google sdk and following the android sdk official documentation, I am in condition to set up a connection with various devices (as pen drives, external HD, usb "phone" etc.), but I am not in condition to connect the android smartphone to usb mouse and keyboard: they are not listed by getDeviceList() method at all, even if android OS is able to recognize and use it!
In fact, I am using the mouse and the keyboard with the mobile without any problem.
I am using for my test a samsung galaxy S4.
Any one can give me some explanation about this, please?
Thank you!
p.s.: I also tried to use app like "USB Host Diagnostic" and the result is the same: the app can not recognize connected mouse and keyboard...but mouse and keyboard are still working perfectly...
Have you looked at Android Open Access Protocol yet? In the section titled HID Support:
The AOA 2.0 protocol adds four new USB control requests to allow the accessory to act as one or more HID input devices to the Android device. Since HID support is done entirely through control requests on endpoint zero, no new USB interface is needed to provide this support.
HTH.