Is it possible to launch two applications with one Intent? For example, broadcast intents fire those who are listening to them.
My idea is to run a watcher while user is browsing websites using android browser. So far, my searches tell me to use intent filter to capture ACTION_VIEW with data "http" or "https". But this isn't what I needed. It will ask users whether they want to use my application to complete action.
Any suggestions would welcome too.
If you want to run something in background, use Service. If you need to have Activity and Service running simultaneously, then start you "watcher" Service in onCreate() and stop it in onDestroy().
You then will need to handle only Activity intent and user will not need to choose anything.
Related
When pressing the call button in the contacts app, I want to launch my own app to call with. The only method I have found to do this is with a receiver that listens to the NEW_OUTGOING_CALL broadcast. But this is ugly and means that all calls are routed through my receiver.
At the moment I have registered multiple intent-filters on the DIAL, CALL and CALL_BUTTON intents, but none fire... I am testing on a Samsung Galaxy S7 with Android 7.
As you wrote: When pressing the call button in the contacts app, I want to launch my own app. . . . then But this is ugly and means that all calls are routed through my receiver, both parts are in contrast.
The best way (and I think the only one since contact app is not "yours", it's owned to OS), is as you did, with a receiver.
What I can suggest to you is to add a custom filter(programmatically) within your onReceive method and to ask when it get awake to ask if the contact is the requested and then open your app via Intent.
I believe that using a Broadcast receiver is actually the recommended way of doing this. It's not possible to actually change the calling application; that's pretty much bound to the OS. Even with a rooted device, you'd have issues.
I want to be able to detect when an application is opened and notify the user of something at the moment related to that same application but I don't know how to do this.
The user opens my app
I intent the service (background / foreground) and it successfully starts
Whenever the user opens another application I want to "catch it" and present a notification to the user
How can this be made? Are there any event listeners i need to use? Thank you very much.
If you are trying to catch "open app" intents in general, then it depends on how the app defined the intent. If it specified a class (explicit intent) then it will generally not be visible to your app unless the device is rooted, for example.
Implicit intents are broadcast and you simply need to define an intent filter in order to receive them. These are intents that allow Android and/or the user to select the appropriate app target based on data sent with the intent.
There are both useful and malicious motivations to do the kind of thing you are asking about. Read this:
Android Intent Security
And also the posted comment on learning about intents overall.
This is really simple. Here I am trying to figure out the solution. When your app goes on onPause() state then broadcast a message using BroadcastReceiver. On the other hand in another app just register for that broadcast.
I currently have 2 apps in the market, let's call them app A and app B.
When a certain function is executed in app, I need something to trigger an event in app a, even if app a isn't currently running. I assume app B would send a broadcast message to app a and app a would need a broadcast receiver but I am not sure how this can be done, if it can be done.
There are basically two ways afaik:
Broadcast Receiver and using the sendBroadcast method on the sender side
or by using Intents:
you can use startActivity(Intent) even with another app, but this will bring the app to foreground rather than doing a job in background.
Use intents if the calling app should dissappear and the called app should be in foreground and use broadcasts if you just want a background task performed by another app
Can be done, even if the app isn't running, with BroadcastReceiver, just like you said.
I'm building an app that collects info about the battery (using background service).
I want this service to start running from the moment I turn on the phone, How do I do it?
On the other hand I want to activate the GUI (interface) of the app only when the user clicks on the app. The app and the background service are in the same project.
Is this the correct way to do what I want?
That is the correct way to do it: see http://www.tutorialforandroid.com/2009/07/permissions-journey-receivebootcomplete.html for info about listening for the BOOT_COMPLETED Intent. You can start your Service in the BroadcastReceiver and then bind to it in you Activity.
Is it possible to detect when an app is executed (i.e., when the user clicks on the app's icon)? I attempted to register an intent of type Intent.ACTION_MAIN using a category of of type Intent.CATEGORY_LAUNCHER hoping this would let me know whenever an app is launched. The problem is, my broadcast receiver is never getting called.
Is this an illegal intent/category combination for which to register? Is there some method I can use to determine when an application launch occurs?
The application start Intent is not a broadcast, so there is no way to register a broadcast receiver and receive it. As previously answered here, there really is no way to detect the launch of the app. You could possibly write a service that polled the running tasks looking for the application's task (using the ActivityManager interface), but that's the best I can think of and it probably wouldn't be very performant.
There aren't any broadcast intent when an application is launched for the general case. If the application you want to detect is yours, you can fire your own intent broadcast, but if not, then no, you can't detect it.