Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using Android.App;
  2. using Android.Widget;
  3. using Android.OS;
  4. using Java.IO;
  5. using Android.Content;
  6.  
  7. namespace BootTest
  8. {
  9. [Activity(Label = "BootTest", MainLauncher = true, Icon = "@drawable/icon")]
  10. public class MainActivity : Activity
  11. {
  12. protected override void OnCreate(Bundle bundle)
  13. {
  14. base.OnCreate(bundle);
  15.  
  16. // Set our view from the "main" layout resource
  17. SetContentView (Resource.Layout.Main);
  18.  
  19.  
  20. }
  21. [BroadcastReceiver(Enabled = true, Permission = "RECEIVE_BOOT_COMPLETED")]
  22. [IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
  23. public class MyBootReceiver : BroadcastReceiver
  24. {
  25. public override void OnReceive(Context context, Intent intent)
  26. {
  27. if (intent.Action == Intent.ActionBootCompleted)
  28. {
  29. Notification.Builder builder = new Notification.Builder(context)
  30. .SetContentTitle("Reboot Notification")
  31. .SetContentText("This is my first notification after reboot the app")
  32. .SetSmallIcon(Resource.Drawable.Icon);
  33.  
  34. // Build the notification:
  35. Notification notification = builder.Build();
  36.  
  37. // Get the notification manager:
  38. NotificationManager notificationManager =
  39. context.GetSystemService(Context.NotificationService) as NotificationManager;
  40.  
  41. // Publish the notification:
  42. const int notificationId = 0;
  43. notificationManager.Notify(notificationId, notification);
  44.  
  45.  
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement