Is it possible to broadcast any message from any Service which is running in background so that any broadcast receiver from that app or any other app can receive the message?
The broadcastreceivers must have some filter and if your broadcast doesn't set this filter your broadcast wouldn't receive the broadcast.
So if you would like to send some message to all of your broadcastreceivers, then all of them should have the same filter properties, but then they are unnecessary.
See the documentation for further details.
When you use sendBroadcast(Intent) or related methods, normally any other application can receive these broadcasts. You can control who can receive such broadcasts through permissions described below.
-> http://developer.android.com/reference/android/content/BroadcastReceiver.html
I don't think so. The service should send a specific message, and only the apps that listen for that message will intercept it.
Related
I want to know all broadcast message that occur at Android system or third-party application.
Broadcast messages that occur at Android system are so easy to know because make broadcast receiver, add intent-filter(all broadcast action) and receive :).
But messages that occur at third-party application are difficult to know because i don't know there broadcast message action :(
How to receive broadcast intent at third-party application?
There is no way to indiscriminately register for any broadcast event, but you can list all historical broadcasts and registered broadcast receivers with the following terminal command:
dumpsys activity broadcasts
Essentially, you would receive only those broadcasts for which you have registered. It is not feasible/possible to receive all the broadcasts. In fact, if it is somehow possible, it would be a HUGE security breach !!!
I have seen a few posts that mention that GCM messages are sent as ordered broadcasts, and that the "android:priority" attribute hence can be used to to control which (out of several) receiver(s) that should handle the broadcast first.
For example: GCM BroadcastReceiver setResultCode use
However, I can't find any doc from Google that confirms this. Regardless of which priority I set on my different GCM-receivers, the broadcast seem to be un-ordered.
Are GCM messages really sent as ordered broadcasts?
I think I've found out why I couldn't control my broadcasts (which led me to believe that GCM broadcasts aren't ordered): I forgot to call abortBroadcast() to prevent the second broadcast receiver from handling the broadcast message:
http://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast() :
Sets the flag indicating that this receiver should abort the current broadcast; only works with broadcasts sent through Context.sendOrderedBroadcast. This will prevent any other broadcast receivers from receiving the broadcast.
So when I call abortBroadcast() only the first receiver handles the broadcast.
From Google Documentation
A "message with payload" is not simply a "ping" to the mobile application to contact the server to fetch data. In the aforementioned IM application, for example, you would want to deliver every message, because every message has different content. To specify a non-collapsible message, you simply omit the collapse_key parameter. Thus GCM will send each message individually. Note that the order of delivery is not guaranteed.
A fellow developer and I have started to question whether a broadcast announcement is guaranteed to be received by the appropriate broadcast receiver.
We have a broadcast receiver which receives messages that should be put on to the screen. Occasionally we notice that some messages never make it to the screen.
Even with the debugger, it has been hard to tell for certain if the receiver is not getting the broadcast or if it due to our own bugs that the broadcast is never sent.
So I wanted to ask generally if there are any known reasons why the broadcast receiver would not receive an announcement?
There are ordered broadcasts in Android. They are sent to receivers according to the receivers priority. And receiver with a higher priority can abort the broadcast spreading.
See this blog post for details.
I am trying to implement an app that will only listen for a certain header in the SMS.
(Parse the sms message and look for some header)
That's not hard to do.
The problem is once the app finds the header and knows this SMS is for me,
I don't want other app(that has broadcast listener on SMS) to receive SMS.
(for example, 'messages' to pop-up with sms message)
Is there a way to listen SMS before any other apps and decide to pass on to other app
or don't pass to other apps?
See one of the answers for the following question Can we delete an SMS in Android before it reaches the inbox?. It explains how to receive the BROADCAST, set the priority of your app so you receive the broadcast first so you could do your checks then cancel the broadcast so no other app receives it.
Read about BroadcastReceiver. You should use ordered broadcast - use android:priority attribute, and then call abortBroadcast() in your BroadcastReceiver.
It is easy to find on google which is the broadcast receiver to listen for sms messages. Is there also a similar receiver to listen for gtalk messages or new emails?
Thanks
Neither of those applications are part of the SDK, so there are no documented broadcast Intents for either action -- sorry!