I have a program that has a broadcast receiver that listens for Phone_State and then sends a user defined intent.
Well, my problem is that the system also sends out an intent (the one that I am trying to replace with my program) .
So I am trying to find a way to CANCEL the systems intent.
I have found that if i have a timer just wait for a little bit, then I can send mine after the systems, but that is not very good, and sometimes defeats the purpose of my program.
Also, i cannot set my program as a default because it is not a full dialer program. Just one action of it.
Someone please help me find how to listen for and cancel a system intent/activity....
Someone please help me find how to
listen for and cancel a system
intent/activity
You cannot "cancel" an activity, period.
You cannot replace the dialer.
If the system Intent was sent via sendOrderedBroadcast(), then you can call abortBroadcast() from your BroadcastReceiver, and any lower-priority receivers will not get the broadcast. However, I have no evidence that ACTION_PHONE_STATE_CHANGED is an ordered broadcast, and I sincerely hope it isn't.
Whatever you are trying to do probably should be accomplished via modifications to your own custom firmware.
Related
I want my app to listen for intends broadcasted by the call application, and when a call intend is broadcasted for a specific number I want to launch a dialog. I read that "A broadcast receiver may not display dialogs, and it is strongly discouraged to start an activity from within a broadcast receiver" https://developer.xamarin.com/guides/android/application_fundamentals/broadcast-receivers/ so I am assuming I should instead make the broadcast receiver launch a service that then launches a dialog. Can anyone confirm this? Also any simplified examples would be highly appreciated
Thanks!
In the example below, the app uses a BroadcastReceiver to detect a phone call number and decide whether it should answer or not:
How to reject incoming call programatically in android?
So using a BroadcastReceiver for that isn't that bad.
If you just want to show information about the phone call, you can display an Notification, as suggested by Jon Douglas in the comments. Displaying Dialogs from BroadcastReceivers isn't allowed (also disencouraged).
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 am going to implement Download Queue for my application. One of its feature will be when Network get connected or disconnected. I want to notify my QueueManger(Service) to update items status and stop.
I know use of Broadcast Receiver and how to use it. My question is if my application is stooped (finished) will broadcast receiver will work? Will it notify application or not?
If not is there any way to achieve this functionality even when application is stooped.
If you register your receiver in the XML instead of programmatically, then it should be able to catch these even when the program is not running.
See question, same solution applies Intent action for network events in android sdk
If you have defined your broadcast receiver as <receiver> in AndroidManifest.xml and listening for android's default action strings, then Yes, it will work.
Otherwise, I would recommend you to make use of Service. It can run silently in the background and do all the logic you want. Your service can even be provoked automatically when the phone is restarted (if you code correctly).
I want to watch for a particular SMS, and handle it in a Receiver when it arrives. I then want to "eat it" so that it doesn't bubble upwards and display to the user (it should be handled "silently"). Is this possible? If so, how?
Is this possible? If so, how?
Since the SMS broadcast happens to be an ordered broadcast, your BroadcastReceiver can call abortBroadcast() to stop it from being handled by lower-priority receivers.
Here is a blog post from a while back discussing ordered broadcasts. Here is a sample project based upon that blog post. Here is a sample SMS BroadcastReceiver that conditionally executes abortBroadcast().
You are looking for the Service construct in Android. It is designed to run something, without requiring a UI (like an Activity).
BroadcastReceiver is additional functionality you should research to catch the SMS event.
I then want to "eat it" so that it doesn't bubble upwards and display to the user (it should be handled "silently")
Huh? Intents that you register to receive are handled silently unless you choose to handle it "loudly".
EDIT
Also, there is no way to prevent other apps from responding to SMS messages. Think about the security implications of allowing one app to control whether other apps can listen for system events...
Yes, it can be aborted by abortBroadcast() method and if you set priority of IntentFilter to 1000(highest priority) then this receiver will receive broadcast before the system.
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.