Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android.App;
- using Android.Widget;
- using Android.OS;
- using Java.IO;
- using Android.Content;
- namespace BootTest
- {
- [Activity(Label = "BootTest", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity : Activity
- {
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- // Set our view from the "main" layout resource
- SetContentView (Resource.Layout.Main);
- }
- [BroadcastReceiver(Enabled = true, Permission = "RECEIVE_BOOT_COMPLETED")]
- [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
- public class MyBootReceiver : BroadcastReceiver
- {
- public override void OnReceive(Context context, Intent intent)
- {
- if (intent.Action == Intent.ActionBootCompleted)
- {
- Notification.Builder builder = new Notification.Builder(context)
- .SetContentTitle("Reboot Notification")
- .SetContentText("This is my first notification after reboot the app")
- .SetSmallIcon(Resource.Drawable.Icon);
- // Build the notification:
- Notification notification = builder.Build();
- // Get the notification manager:
- NotificationManager notificationManager =
- context.GetSystemService(Context.NotificationService) as NotificationManager;
- // Publish the notification:
- const int notificationId = 0;
- notificationManager.Notify(notificationId, notification);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement