You do not have to explicitly set Exported = "true"
since you already have at least one intent filter so it is redundant. Your permission is also missing from your receiver, which is required. Don't manually edit your AndroidManifest.xml
because it will be overwritten by Xamarin.
You also have to configure any battery optimization service that your mobile phone is running example Huawei. You have to disable battery optimization for this app otherwise it will not receive any broadcast.
After installing the application, you have to open it from the icon at least one time, otherwise it will be delivered any broadcast by the Android System.
Sample Code:
namespace AZ.Sample.Notifications
{
using System;
using Android;
using Android.App;
using Android.Content;
[BroadcastReceiver(Enabled = true, Permission = Manifest.Permission.ReceiveBootCompleted)]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.LowPriority, Categories = new[] { Intent.CategoryDefault })]
public class BootBroadcastReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(Android.App.Application.Context, "Broadcast Received", ToastLength.Long).Show();
var uri = Android.Net.Uri.Parse("http://www.google.com");
var intent1 = new Intent(Intent.ActionView, uri);
intent1.AddFlags(ActivityFlags.NewTask);
intent1.SetPackage("com.android.chrome");
try
{
context.StartActivity(intent1);
}
catch (ActivityNotFoundException ex)
{
ex.PrintStackTrace();
//Chrome browser not installed
intent.SetPackage(null);
context.StartActivity(intent1);
}
}
}
}
Chrome should be installed on the mobile device on which you will run this sample code, after restarting the device don't let it sleep and wait at least 2 minutes. After that it will show a toast message and also open a website in Chrome browser.