How to send serial data via Bluetooth to an unspecified device? - java

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.

Related

Turn on mobile earpiece forcefully

Following is the scenario:
Headphones with mic are connected to a mobile device.
What i want to achieve programmatically:
After a call is been initiated, audio from 3.5mm jack should (forcefully) be routed to mobile earpiece rather then headphone speakers, while the mic should be used of the headphones.
I have searched a lot on google but found methods only to forcefully turn on mobile external speakers.
Reference : how to turn speaker on/off programmatically in android 4.0
While, my goal is to turn on earpiece forcefully.
My research from google:
To achieve this there might be possibilities of system (root) permissions, which a third party application might need.
You may have to write a modified audio driver from sources ? As the functionality is based on the operating system.
If it is possible, can any one guide me on this ?
UPDATE
One more reference: Android - Getting audio to play through earpiece
But the above code does not work on all phones.

Connection to HID USB device (keyboard and mouse) in android

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.

Is it possible to receive a signal over 315 MHz on an Android device?

I want to make an android application that will receive basic data transmitted from a RF Link Transmitter (https://www.sparkfun.com/products/10535?). I want to know first off if it is possible to somehow control what frequency you can receive a signal on.
I want to know first off if it is possible to somehow control what frequency you can receive a signal on.
Generally, no. Android is an operating system. It is not hardware. Specifically, it is not a software-defined radio (SDR) receiver. In principle, Android could power a device that had SDR capabilities, but Android itself has nothing related to SDR, certainly at the SDK level. Or, Android could power a device that happens to have a suitable 315MHz receiver, but your general off-the-shelf Android device probably does not have such a receiver, and the OS does not have anything specific for that sort of receiver.

How to emulate/test bluetooth chat?

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

How to interoperate between PC and camera from cell phone

My new project is to build an application to use the cell phone camera as the main camera from my PC.
How can I do this kind of stuff?
I thought of using bluetooth, but how my PC define the cell phone as the main camera?
Best reguards.
Depending on the camera phone and its features, you can do it. For my Bluetooth efforts, I've been using A7 hardware and a .NET library Blue Tools from Franson.
I've been able to:
pair devices in code
send/push images to the phone (probably the reverse would work, but I didn't try)
discover devices automagically
serial comm
network com
install as a network driver
Well on the Bluetooth side of things you might need a program running on you phone to forward the images. Or you might find that there's a Bluetooth program already running and providing that service, for instance the Bluetooth BASIC IMAGING PROFILE (BIP) (1) profile includes the usage scenario: "Use of a mobile phone to control the shutter of a digital still camera and immediately examine the result on the phone’s screen. In the present scenario, any other portable imaging device could play the role of the mobile phone."
So first you need to find if the phone supports BIP. You could for instance use the SdpBrowser sample application in my 32feet.NET .NET Bluetooth library to see what services the phone is advertising. Otherwise perhaps its documentation will tell you. You'd then have to find out whether the BIP service on your phone supports that scenario.
On the PC side you might need some driver level software to allow any application to use the remote camera. You might start by just allowing your own application alone to use the camera.

Categories

Resources