Launch app with intent when calling contact - android

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.

Related

Receivers Receives Intent several times

I'm building an app on an android Professional device (not a smartphone or a mobile). I have a problem that drives me crazy..
I've registered my receiver only once. I destroy it when the activity is destroy.
To be sure, before register for it, I've wrapped an "unregisterReceiver" in a "Try and Catch".
But, unfortunately, My intent is sent only once (log confirms that) and my receiver receives it twice.
So how to avoid that?
It runs with Android 10.

Detect when app is opened with a service

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.

android.intent.action.BOOT_COMPLETED - do not receive broadcast if boot completed by a phone call

I am using a broadcast receiver in my app, to display a photo on BOOT_COMPLETED. However, I noticed that if I receive a phone call on my phone, the photo is displayed in front of incoming phone call activity, so I can's see who is calling me and what is worse - can't answer the phone.
What is the best way to override this behavior?
you could add another mechanism for listening to phone calls events, and if you detect that the phone is ringing (or the call was answered), you won't show the activity...
in any case, please don't show such things. no user likes popups go out of nowhere.
instead, use notifications to tell the user something has happened.

how to make server call whenever device screen is turned ON without Service

This requirement is only satisfied if the app is running in the background.And if the Screen is turned on if the user presses to check any notifications then an Asynctask is called if the app is running in the background and makes a call to the server.
I have tried using Broadcast Receiver when screen on and tried to execute, it works only if the app is on the front screen after pressing the home button .And then if the user presses Power button after an hour then nothing happens .
Basically I am not sure if the app is being killed after sometime when in background. Please help me.I am a noob in Android and this functionality is something I thought most of the developers might be using but I did not see anything except service calls and I really did not want any service/alarm-manager as I don't want it to work continuously.
TIA
how to make server call whenever device screen is turned ON without Service
This is not possible. ACTION_SCREEN_ON is a broadcast that can only be received by a BroadcastReceiver registered via registerReceiver(). So, unless you are the foreground activity, the only way you can receive this broadcast is via an always-running service, which is not a good idea.
as I don't want it to work continuously
Then do not "make server call whenever device screen is turned ON". Find some other solution for whatever business problem you have that you are trying to solve this way.

How can one detect an Android application launching?

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.

Categories

Resources