Struggling a bit with Android >=10's UsbDevice class and detecting re-attachment of the same USB device. Prior to Android 10, I could use UsbDevice.getSerialNumber to get a unique handle for a USB device (if it had one). UsbDevice.getDeviceName tends to change from attach to attach e.g. /dev/bus/usb/001/002, /dev/bus/usb/001/003. For Android >=10 you need to ask for user USB permission before calling getSerialNumber. Without having a manifest intent filter for the USB device type and saving the App as the preferred client this is now very messy - a new Permission Request dialogue is needed for each re-attach. Has anyone found a workaround for this? USB OTG connectors are not the most secure so yank then re-plug is a reasonable thing to want to do.
Related
In an Android app, I need permission for a specific USB device (known vendor/product ID), which is permanently plugged on the Android device.
So far I've made the following observations:
when using UsbManager.requestPermission() the permission is dismissed when replugging/rebooting and the popup's checkbox seems to have no effect at all on this behavior
when using intent filters, the permission is properly re-granted when replugging the USB device (even when replugging after a reboot, if the popup's checkbox was checked) BUT the permission is not re-granted after reboot unless I unplug & replug the USB device.
Is it possible to make sure that the permission popup is displayed only once ? (especially in the scenario when the Android device is rebooted and the USB device remains plugged in)
NB: the app isn't installed in the system folder and therefore cannot use the MANAGE_USB permission.
The solution is to use intent filters and add the android:directBootAware="true" attribute on the associated activity so that the USB_DEVICE_ATTACHED event is correctly received after boot.
Persisting USB Permission is not possible, as the reboot option is stopping everything forcefully generally it makes the USB also unplugged.
There is one possibility to ask for replugging USB on reboot.
Is it possible to make sure that the permission popup is displayed only once? No
Because If your are connecting the usb which makes a deadlock situation for taking care of that they make it unplugged, rather than disturbing the system.
So it is not possible to make it USB Plugged-in.
My device is such that my android app is always connected to an Arduino board through a USB. On device reboot my Android app forgets the USB permissions granted using intent filter in the manifest. I want my app to remember permissions for communicating with the Arduino board across power on/off cycles (Something that it is currently not doing).
So I found out that there isn't a way to go about it yet. So thank you for your time.
I am working on a project where I need to put a USB device in to a reprogramming state and then send a software update to the device. I have been able to make this work by having the user disconnect and reconnect the USB cable between the android device and the USB device I am reprogramming. I have attempted many combinations of releasing interface and then trying to loop through the USBManager getDeviceList and then requestPermission on that device again. I have tried modifying the PendingIntent to be different than the original PendingIntent. I thought I had it once but it seems to have been a faulty OTG cable. In a last ditch effort I tried to craft my own android.hardware.usb.action.USB_DEVICE_ATTACH/DETACH message (which I got a Permission Denial on) Any other ideas out there or is it just not possible?
Some background information:
I have a certain yet to be released tablet and sadly the people who designed it seemed to have removed TelephonyProvider.apk
Here's how I've reached that conclusion :
When I go to More... in WIRELESS & NETWORKS there are no options to change APN, VPN or access Mobile networks. (Please note that the table has no facility to lodge a SIM card) However, on my Karbonn ST10 (Android 4.1.1) all these options are found. The certain tablet is currently on Android 4.2.2
When I used an app called APN shortcuts I was able to launch the APN configuration screen, however every time I changed the MCC or MNC number, the APN could not be saved and was deleted.
When I tried to read the contents of content://telephony/carriers I received a NullPointerException.
Questions:
What is the purpose of TelephonyProvider.apk?
Will it be possible to install it without root access? If so, how? (I'm pretty sure this can't be done, but if someone else knows a magical method please enlighten the world)
Can 3G data connections via dongles be established on this device which seems to be missing TelephonyProvider? Or will the ROM have to be edited and TelephonyProvider be installed.
I'm pretty sure this is a programming question, but if it belongs on Android Enthusiasts, please move it.
It's just an apk... you should be able to sideload it with adb without root with adb sideload <your apk>. It would just be removable since its not it /system/app, ie built in with the ROM. If the makers of your device disabled certain features on the device, which would explain possibly why those menus do not display in the Settings app, then TelephonyProvider may not be all that you need to get the connections you want to establish working.
Hope this helps.
Update:
These features are probably disabled on the device you are using. based on what you described.
From the PackageManager documentation.
FEATURE_TELEPHONY Feature for getSystemAvailableFeatures() and hasSystemFeature(String): The device has a telephony radio with data communication support.
FEATURE_WIFI Feature for getSystemAvailableFeatures() and hasSystemFeature(String): The device supports WiFi (802.11) networking.
I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices
which is allot of help on how to pair,connect to a bluetooth device.
I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?
Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.
Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?
Some suggestions though:
If you can make your BT devices discoverable at all, you could do it this way:
Make your BT device discoverable
Let Android search for and find the device and then initiate a connection
Android will ask for the PIN for pairing with the device; enter the PIN.
Once pairing was successful, Android stores the pairing information for future use, so that you can
Make your BT device invisible again.
From then on your app should be able to connect to the BT device at any time without further pairing operations.
If the said is not an option for you, maybe you want to go another way:
In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("#hide"...) APIs, either via reflection or via modification of your SDK installation.
But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.
Having said that, here comes some reference:
Example of how to access "hidden" bluetooth API.
Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.
In there, public boolean createBond(){...} may do what you want.