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
Related
Situation:
VS 2022, 17.0.4
Maui App,
net6.0-android
AndroidManifest.xml contains also:
android.permission.INTERNET
android.permission.CHANGE_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
Connected mobile Phone:
Samsung SM-G960F (Android 10.0 - API 29)
OS: Windows 11, latest patch.
All firewalls are down (for testing purpose only!)
While debugging the develop computer is only connected to a Wifi network; computers ethernet card is disabled.
Mobile phone is connected to this dev computer via USB cable (to be able to debug) and to the same Wifi network as the computer.
App starts and works fine, app can be debugged. No issue at all - except:
After the application is fully initialized and ready to accept user interactions -> Click on button -> Desired method is called -> Code is worked out -> The code should make a simple UDP call but it does not (or the packet does not reach the UDP listener due to missing configuration?).
The UDP receiver works fine and is capable to receive UDP packets.
My mobile phone and the UDP receiver app are using the same port.
I read/found already that in the previous cross-platform framework, means “Xamarin (Android SDK 12)”, some permissions must be set (I did, see above) and that the multicastlock must be set over the WifiManager …
I tried this in my MAUI app. But could not find anything guiding me nor figured it out by myself.
My MAUI sending code:
var dataToBeSend = "What ever ...";
var data = Encoding.UTF8.GetBytes(dataToBeSend);
var UdpClient = new UdpClient();
// UdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
UdpClient.ExclusiveAddressUse = false;
UdpClient.EnableBroadcast = true;
// UdpClient.Client.Bind(new IPEndPoint(IPAddress.Parse("255.255.255.255"), BroadcastPort));
// UdpClient.Client.Bind(new IPEndPoint(IPAddress.Any, BroadcastPort));
UdpClient.Send(data, data.Length, "255.255.255.255", BroadcastPort);
As said: very easy and straight forward.
Notice that I also tried binding UDP code …
So please can someone be so kind to guide me or give me a hint?
Thank you very much in advance!
ANSWER:
After two days I found a solution - and would like to share it because may be it helps someone else.
The code to make the UDP call msut be placed in a THREAD (not task!)
codesnippet:
var communication = new Communication();
var udpThread = new Thread(new ThreadStart(communication.FireUDPCall));
udpThread.Start();
The firewalls can stay turned on / active!
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!
I have a problem with testing my application on Android platform. I have functional application on x86 architecture. This application can connect to Bluetooth LowEnergy device and communicate with it. BT device is HM-10 module - serial line.
But when I try the same application, but just compiled for Android, I'm not able to receive any data back. On the other hand I can see on remote device that all data from mobile terminal are sent.
What I suspect as a possible problem is that signal QLowEnergyService::characteristicChanged is not emitted. In the documentation http://doc.qt.io/qt-5/qlowenergyservice.html is written that you should register for changes, but at least on PC it is done automatically somehow.
Would anyone please help me ?
You have to do some magic
QLowEnergyDescriptor notification = _characteristic.descriptor(
QBluetoothUuid::ClientCharacteristicConfiguration);
if (!notification.isValid()) {
qDebug() >> "QLowEnergyDescriptor not valid";
}
connect(_service, &QLowEnergyService::characteristicChanged, this,
&Device::onCharacteristicChanged);
_service->writeDescriptor(notification, QByteArray::fromHex("0100"));
I have a bluetooth hid device that I need to communicate with. Target platform is Android 5.x+. Currently testing on Nexus 7 2013 tablet.
My code works fine on android 5.x, I am able to receive, send and set reports on Android 5.x.
On Android 6.x, I am only able to receive reports sent by device, but I am not able to send or set reports. It looks like my set/send report requests are silently ignored by HID/BT stack.
The code that talks to /dev/hidraw* nodes runs as a native daemon as root.
Are there any new requirements to be able to set/send reports to Bluetooth hid devices on Android 6.x? Is there any changes I could make to AOSP to allow this to work?
[Update]
Logcat says:
05-17 11:22:56.085 2455-4061/com.android.bluetooth E/bt_btif: uhid_event: Invalid size read from uhid-dev: 4108 != 4
I do not understand how reading from uhid will return only 4 bytes! First 4 bytes are supposed to contain only the type of event. Is there any scenario that will result in a read() of less than sizeof(struct uhid_event) bytes?
Could this indicate a bug in uhid driver?
I checked available kernel sources and found that hidraw driver does not contain usable source to feed reports to /dev/hidraw* nodes
I also found that Bluedroid correctly receives and sends reports internally.
Simplest method to get/set/send reports I found was to modify bluedroid to communicate directly with my App for vendor-specific reports. I integrated my daemon into Bluedroid directly.
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...