How to auto launch an application on an android event - android

I have an application which can explore the file system of android and the devices connected to android.
I want my app to get launched automatically on an event-specifically whenever a usb storage device is connected.
I have tried giving device filter list and it does the task but the application gets launched only for devices that are mentioned in the device filter list. How can I achieve the same for all usb devices-application should launch itself automatically for every usb device connected,

Related

How to use the USB_DEVICE_ATTACHED intent-filter in Android for a USB device that is always connected

I have a scenario where I want an app to open when it detects that it's connected to a USB device. I have used an approach similar to this (it is using a USB_DEVICE_ATTACHED intent-filter and I have the ID's defined in an xml) and it is working for the most part. The problem I'm having is that when the Android Tablet powers on, the tablet will already be connected to the USB device, so the app doesn't get the USB_DEVICE_ATTACHED event. This then requires me to start the app manually after power up, which leads to me getting this unwanted dialog screen each time:
Allow App to access USB?
[ ] Always open App when USB is connected
Cancel OK
It makes no difference if I check the "Always open" box. It still shows up each time. I have tried using a broadcast receiver to open the app when the app powers on, and I still get the dialog window.
So I'm wondering:
Is there is a way to see get a USB_DEVICE_ATTACHED event when I first power on?
Or is there a way to not display the unwanted dialog screen each time I open the app manually?
I would really appreciate any suggestions. Thanks!

Can I launch a specific app when android device get physically connected to a specific usb device?

Can I "register" a (already installed) specific app to be launched when android device get physically connected to a specific usb device ?
Eg.
I connect a keyboard (of a certain brand or with a special USBid/class) and it automatically launch a text editor app
I connect an USB soundcard and it launches an audio app.
And "better", is there an autolaunch on Android ? I plug a keyboard+storage device to my smartphone and Android will ask me if I want to install the apk from the storage (or download it from predefined url)
Obviously for security reasons I understand installing the app from the storage will need confirmation by user. But, once the app has been "registered" would it be possible to launch the app automatically without having a confirmation screen ?
I know I could get USB info with android.hardware.usb.usbdevice. My question is more about how I can tell Android to launch this app rather than another when usb device is connected.
I think you could register your app to receive a system broadcast like USB_ACCESSORY_ATTACHED and make the logic to launch your app when this happens.
Check https://developer.android.com/guide/components/broadcasts
https://developer.android.com/reference/android/hardware/usb/UsbManager.html#ACTION_USB_DEVICE_ATTACHED

Android - How to use the same USB device with two apps running simultaneously?

I am developing two apps that use the same USB device, but serve different purposes. The USB driver for both apps are the same, however, I would like it to where both apps can be running simultaneously while using the same USB device.
Unfortunately, as of right now, when using the USB device in App A, App B loses communication with the device when running in the background with App A active and receiving data. I would like both Apps A and B to receive the same data simultaneously with one app active while the other is running in the background.
I wonder, is this even possible?

Can't disconnect BLE devices when killing the app with background plugin on

I'm developing an app that interfaces with BLE devices using this plugin.
Inside the app, I can pair the devices and monitor their status.
If I close the app I want to disconnect the devices from the smartphone, and when I open it again, I want the app to reconnect automatically to known devices.
Everything works fine without using the background plugin, but I need to use it since the app needs to monitor the BLE devices even when it's in the background.
The problem happens ONLY if I use the background plugin: if I open again the app, the known devices are not reconnected INSIDE the app, but it appears they are already/still connected to the smartphone from the previous time (even if not shown in the Bluetooth devices in the phone settings).
It seems that the Bluetooth connection to known devices isn't really being closed when I kill the app.
It appears like the device is still connected as therefore it doesn't show up when I scan in the app.
I can't reconnect until I close the app, switch off and then on again Bluetooth, and reopen the app.
The steps are very simples:
I open and connect the first time from the phone to the BLE product
Communication is OK, data is sent and received
I close (kill) the application from the smartphone (Without turning off Bluetooth/BLE from smartphone)
I relaunch the application ---> Known device is not reconnected but appears to be somehow still paired with the phone (if I press the pairing button it does not go into pairing mode, that happens if it is already bonded to a phone).
Why this behavior? Looks like something in the background plugin prevents the Bluetooth connection to be closed on app closing. I specify that:
it only occurs using the background plugin, without it activated everything works ok
this behavior occurs only with Android (don't use the background plugin for iOS)
it does happen only on some Android smartphones: tried three different phones, with Android version v4.4, v5.1.1, and v6.0.1, and only two of them show this issue (android version 4.4 on S3 and 6.0.1 on S5 Neo).
Thanks

Android app to send and receive a file automatically when get connected via bluetooth

I am new to android world.I want to design an android app in which all connections will be through bluetooth. It will works as follows
as I click some button like start it will connect to one of the paired devices(mobile) and get a file, store it somewhere and eventually disconnect with that device.Then it will connect to the second device, get a file, store it and then disconnect with that device and so on. It will repeat the same procedure for all the paired devices.
And later on I will replace those paired mobiles with sensors and will collect the the data.The whole process should be automatic without user's intervention.
Guys please help me. Is it possible for a mobile to send a file automatically as it connects to a particular mobile.

Categories

Resources