What exactly is a broadcast intent? How is it different from a regular intent?
What are the differences between explicit and implicit broadcast intents?
What does the Intent Sniffer application mean when it says
"the Intent Sniffer tool performs monitoring of runtime routed broadcasts Intents. It does not see explicit broadcast Intents, but defaults to (mostly) unprivileged broadcasts."?
Broadcast intents are intents used to trigger BroadcastReceivers having an Intentfilter matching the broadcasted intent.
This is triggered with Context.sendBroadcast as opposed to other intents that are often used with Context.startActivity.
A broadcast intent could be received by multiple receivers while other intents will be caught by a specific activity (perhaps at the user's choosing).
I guess Intent Sniffer simply listens to all broadcasts it can get its hands on by registering a few receivers with wide intentfilters.
Related
My code below doesn't work on androind 8.0+, but works before 8.0.
Thus, it seems it is treated as an implicit broadcast.
[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { "notpackagename.com.IntentReceiver.MySampleBroadcastReceiver" })]
public class MySampleBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
String value = intent.GetStringExtra("key");
Console.WriteLine(value);
}
}
var intent = new Intent("notpackagename.com.IntentReceiver.MySampleBroadcastReceiver");
intent.PutExtra("key", "MySampleBroadcastReceiver");
SendBroadcast(intent);
I want to know what is defined as Explicit broadcast or Implicit broadcast?
Because I need the app to receive message when it is not running, like below:
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
The primary difference between the manifest-registered receiver and
the context-registered receiver is that a context-registered receiver
will only respond to broadcasts while an application is running, while
a manifest-registered receiver can respond to broadcasts even though
the app may not be running.
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
Android identifies two types of broadcasts:
Explicit broadcast – These types of broadcasts target a specific
application. The most common use of an explicit broadcast is to start
an Activity. An example of an explicit broadcast when an app needs to
dial a phone number; it will dispatch an Intent that targets the Phone
app on Android and pass along the phone number to be dialed. Android
will then route the intent to the Phone app.
Implicit broadcast – These broadcasts are dispatched to all apps on
the device. An example of an implicit broadcast is the
ACTION_POWER_CONNECTED intent. This intent is published each time
Android detects that the battery on the device is charging. Android
will route this intent to all apps that have registered for this
event.
Update
Please correct me if I am wrong:
Based on the description below, MySampleBroadcastReceiver above is manifest-registered receiver, so it should be able to receive message. But it is not even working. I have to change it to dynamic registration.
An intent filter is used to register a broadcast receiver so that
Android can properly route messages. The intent filter can be
specified at runtime (this is sometimes referred to as a
context-registered receiver or as dynamic registration) or it can be
statically defined in the Android Manifest (a manifest-registered
receiver).
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers
What is defined as Explicit broadcast or Implicit broadcast?
Explicit broadcast
The sent Intent is a broadcast that shows the Intent. By specifying the name of the Intent component, it is generally used to know the name of the target component, to call the following method. The intent is clear, specifying which component is to be activated, which is typically implemented inside the same application.
Intent.setComponent()
Intent.setClassName()
Intent.setClass()
new Intent(A.this,B.class)
Implicit broadcast
It is implemented by Intent Filter, which is generally used without explicitly indicating the name of the target component. The Android system will handle this intent by finding the most appropriate component based on the action, category, data (URI and data type) set in the implicit intent. Generally used between different applications
Your code is Explicit broadcast
I need the app to receive message when it is not running
Based on my research, it cannot be achievd in Explicit broadcast, If application is closed, Explicit broadcast will be closed.
If you want to achieve application receive messages from server and it will not closed by the Android system, I suggest you to Start the service in the foreground like this link.
How to create service doing work at period time in Xamarin.Forms?
I have a network change receiver class and it extends from broadcast Receiver, but I’m not pretty sure that it’s working in android Oreo, does Oreo support broadcast receiver, and if it doesn’t support, what’s the other way to do it
Oreo supports Broadcast Receivers but with some restrictions on Implicit broadcast that are declared in manifest.
Implicit vs Explicit Broadcast:
According to the documentation, an implicit broadcast is a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED is an implicit broadcast, since it is sent to all registered listeners, letting them know that some package on the device was replaced.
However, ACTION_MY_PACKAGE_REPLACED is not an implicit broadcast, since it is sent only to the app whose package was replaced, no matter how many other apps have registered listeners for that broadcast.
So any broadcast receivers that we have defined statically within our application manifest that are listening for implicit broadcasts will no longer receive those broadcasts.
The reason for this change is that implicit broadcasts would previously trigger any component that was listening for them within the manifest— this could have an adverse effect on application and device performance due to large numbers of applications registered to receive specific broadcasts all being triggered at the same time.
But there is a list of exceptions when it comes to implicit broadcasts — this means that there are still some which you can register to receive broadcasts for. They are all listed below:
So if the broadcast that you have registered receivers for is on this list, then it will still function as it did previously. However, if the broadcast that you have registered to receive is not on this list then you should use some alternative solution like:
Create the receiver at runtime by calling Context.registerReceiver(),
instead of declaring the receiver in the manifest.
Use a scheduled job to check for the condition that would have
triggered the implicit broadcast.
For more information
It's not supported in Oreo as manifest tag, you must have to register it at an Service/ Activity with context.registerReceiver(). Or you use the WorkManager to schedule something for specific network conditions.
Helo,
As is described Broadcast Limitations Android O comes with some limitations on implicit broadcasts, by definition broadcasts received by DeviceAdminReceiver are implicit also it are not in Implicit Broadcast Exceptions, although however, MyDeviceAdminReceiver continue receives broadcasts without dynamic registration.
Should I consider that it are explicit broadcasts ?, or it should be dynamically registered ?
Thanks in advance.
Should I consider that it is explicit broadcasts ?
Yes. Just because an Intent has an action string does not make it implicit. What makes it implicit is not having a ComponentName or package to constrain where the Intent gets broadcast.
In this case, since not everything can listen to those broadcasts, the system is filtering the list of registrants to those eligible to receive them, and is using explicit Intents to only send the broadcast to the eligible receivers.
I'm confusing about these question.please help me in these question
Many applications registered the broadcast receiver with the same action and one application send the broadcast then what will happen?
Does all apps will receive the that intent or only one app will receive the intent ?
can we registered the multiple receivers in the same application?
if we registered the two receivers with same action in the same application then what will happen?
All receivers will receive the broadcast.
Broadcast Receivers are designed to provide notification about a single event to multiple receivers.
There is only one exception to this statement, if a broadcast is an Ordered broadcast, then the broadcast will be propagated sequentially to all receivers one after another(based on priority) and any of the receiver can decide to prevent broadcast from propagating further. The broadcast receiver for SMS is a good example of ordered broadcast.
Yes, multiple receivers can be registered in the same app.
Both the receivers will receive the intent as expected.
I'm coming up to speed on Android development and the distinction between an implicit intent and a broadcast receiver is unclear. I was hoping for help in distinguishing these concepts and when to use the two.
Both receive intents, both react to system messages, so why is a broadcast receiver even needed and when is it used as opposed to an implicit intent and intent filter to accept the implicit intent?
Broadcasts are just that -- messages broadcast to anyone listening. They are inherently insecure, and delivery to the intended recipient isn't guaranteed, because there really isn't an intended recipient. For example, the CONNECTIVITY_CHANGE broadcast makes this quite clear: When connectivity changes in an Android device, many apps might be interested. Rather than the ConnectivityManager having to notify each app via specific Intent, it sends a broadcast. Any app that has registered interest in this event will be notified. Any app that isn't running or doesn't care... won't.
An Intent is "sent" when one app or Activity wants to launch another to do something very specific. For example, a file-manager might want to launch an image viewer or video player. Your app might want to launch a very specific Activity within another one of your apps, etc. The communication by specific intents (i.e. including package name and component name) can not easily be intercepted, so it's somewhat more secure. Most importantly, there's only and exactly one "receiver" -- if none can be found, the Intent will fail.
Further, a BroacastReceiver will be active within an Activity or Service and received broadcasts will generally only change state and/or do minor UI updates... for example, you might disable a few actions if your internet connectivity is dropped. By comparison, a specific Intent will usually launch a new Activity or bring an existing one to the foreground.
I am going to compile a list here of all the differences between Implicit Intents (sent via startActivity()) and Broadcasts (sent via sendBroadcast())
Broadcasts, by default, can affect multiple applications at once (Ordered Broadcasts have the potential to be disrupted). In contrast, Implicit Intents will only affect one application. Please note that there may be multiple possibilities of applications that could be affected, but eventually only one will be.
Implicit Intents are handled via Intent-Filters, and Broadcasts are handled via Broadcast Receivers (albeit the intent-filters play a role here too). I have seen in many instances over the web that Broadcasts are compared to Intent-filters and that does not make sense to me.
An Implicit Intent launches an Activity, or a Service. By contrast, a Broadcast launches a Broadcast Receiver. (This, if you think about it, is the core difference between Intents and Broadcasts. It is because of this reason that Broadcasts aren't meant to do too much heavy work, and especially not UI work!)
From the Developers Website:
There is no way for a BroadcastReceiver to see or capture Intents used
with startActivity(); likewise, when you broadcast an Intent, you will
never find or start an Activity. These two operations are semantically
very different: starting an Activity with an Intent is a foreground
operation that modifies what the user is currently interacting with;
broadcasting an Intent is a background operation that the user is not
normally aware of.
I'll add more if I find anything else.