I am working on using the USB_DEVICE_ATTACHED intent on an app. The app works fine, but I would like to open it with another app to start using the device.
I'm wanting the app to launch either hidden or in the background (not launch on top of the already running app). I've seen some use services for this, but it looks like USB_DEVICE_ATTACHED (and the other usb intents/permissions) don't work on a service.
Have your broadcast receiver call the service when it receives that particular intent action and then start your service.
Update
Read the great link provided by CommonsWare:
http://developer.android.com/guide/topics/connectivity/usb/host.html
Ended up using an activity with the NoDisplay theme.
Related
I have a device management application, which essentially runs as a service in the background from boot. I'd like to start this application immediately after installation. How do I achieve this?
You cannot do this -- there is no way to automatically start your service merely because it was installed.
The application must first be invoked by the user through some sort of activity. Or, you are going to need to hook into some relevant broadcast Intent via the manifest, so you can get control when one of those events occur and kick off your service that way. Or, you are going to need to ask the user to reboot so your BOOT_COMPLETED Intent filter can get control.
There was a hole - the Android Analytics SDK used to send an intent right after installation - but that got closed (producing lots of confusion, of course).
But the final answer, I believe, is here:
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
This seems to suggest that, as of 3.1, Google made the decision that apps are in a stopped state until the user explicitly activates them, e.g. by launching app or placing widget.
This means that the strategy of listening of a common broadcast (i.e. to get your app launched surreptitiously) won't work either.
I know the android broadcasts an Intent to start an activity. I can use a Broadcast Receiver to receive that intent. But what is the actual way of receiving an intent if an app starts in Android as I don't know what can be the actual intent for an app be (Means I can get the list of installed android applications but how to know what intent will be broadcasted if a particular app starts) .
EDIT :
I'm just adding this as a feature in my phone that if a game launches, then the Immersive mode will automatically be opened. I've system priveleges as well (as I can make the changes in SystemUI or frameworks as well). I don't want to touch the Launcher though.
by this way . But it's still a little bit weird as solution . I don't think there's any simple way to do it...
How to start an application that has no launcher activity?
Story behind the problem:
I have an application that is basically a BroadcastReceiver that waits for a couple system intents like BOOT_COMPLETED. The problem is that as my application has no Activity, it doesn't get started and so it receives no intent.
Android 3.1 release notes mention that intent options can be overridden to start up applications but I assume it requires another active application to do so.
P.S. Write all the ways you know. ADB commands as well.
First piece of advice would be to make a very simple "Welcome to my App" Activity that could be run. Use it to show a splash screen, some advertising, or be a settings screen. That gets you around the "no Activity" problem.
As far as I know, you cannot have anything hooking into BOOT_COMPLETED until and Activity in your application has been run. So you need to have an Activity of some sort.
I am new to android development. I want to make one background application, so that it keeps running in background, and it's without any UI, and even its icon do not appear on desktop.
In short it's a stealth application.
Is it possible?
This is certainly possible. To create an app that does not have an icon in the launch pad, just remove the Activity with the android.intent.category.LAUNCHER category from the AndroidManifest.xml.
To implement your background application it strongly depends on what you want to do. You can create a Service for long running tasks, BroadcastReceivers to react to specific events or Activities with intent filters.
Be aware, however, that your application will be visible in both the file system and in the settings under 'Manage Applications'.
Yeah it's possible look up Service
Read more about the service in tutorials
ServicesDemo - Using Android Services
How Android Services Work
Android Service creation and consumption
I have a device management application, which essentially runs as a service in the background from boot. I'd like to start this application immediately after installation. How do I achieve this?
You cannot do this -- there is no way to automatically start your service merely because it was installed.
The application must first be invoked by the user through some sort of activity. Or, you are going to need to hook into some relevant broadcast Intent via the manifest, so you can get control when one of those events occur and kick off your service that way. Or, you are going to need to ask the user to reboot so your BOOT_COMPLETED Intent filter can get control.
There was a hole - the Android Analytics SDK used to send an intent right after installation - but that got closed (producing lots of confusion, of course).
But the final answer, I believe, is here:
http://developer.android.com/about/versions/android-3.1.html#launchcontrols
This seems to suggest that, as of 3.1, Google made the decision that apps are in a stopped state until the user explicitly activates them, e.g. by launching app or placing widget.
This means that the strategy of listening of a common broadcast (i.e. to get your app launched surreptitiously) won't work either.