broadcast intent callback: result = CANCELLED

GerryHGerryH USMember ✭✭✭
edited April 25 in Xamarin.Forms

My app can receive FCM messages and display a notification okay.
My app can receive a system boot and display a program notification okay.
When my app starts from system boot, attempting to display a notification after receiving an FCM messages causes a crash. Works fine if I manually launch the app after system boot.

Is there a demo app on github that can do all these things?

I tried posting my code, but https://forums.xamarin.com seems to have bugs that prevent me from posting.

Best Answer

  • GerryHGerryH US ✭✭✭
    Accepted Answer

    Nevermind, the error had nothing to do with result = CANCELLED

Answers

  • GerryHGerryH USMember ✭✭✭
    namespace com.foo.bar
    {
       [BroadcastReceiver]
       [IntentFilter(new string[] { Intent.ActionBootCompleted })]
       public class BootReceiver : BroadcastReceiver
       {
          const string TAG = "tyresense.bootreceiver";
          public override void OnReceive(Context restrictedContext, Intent intent)
          {
             var splash = new Intent(restrictedContext, typeof(SplashScreen));
             MyNotification.CreateProgramIcon(Application.Context, splash); // works fine
          }
    }
    
  • GerryHGerryH USMember ✭✭✭
    namespace com.foo.bar
    {
       [Service(Exported = true)]
       [BroadcastReceiver]
       [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
       public class FireMessagingService : FirebaseMessagingService
       {
          const string TAG = "whatever";
    
          public override void OnMessageReceived(RemoteMessage message)
          {
             Log.Debug(TAG, "Incoming FCM from: " + message.From);
             var intent = new Intent(this, typeof(SplashScreen));
             MyNotification.SendNotification(this, intent, message.Data, true, false); // works fine, but only if app started by user
          }
       }
    }
    
  • GerryHGerryH USMember ✭✭✭

    Is it necessary to use JobIntentService?

  • GerryHGerryH USMember ✭✭✭
    Accepted Answer

    Nevermind, the error had nothing to do with result = CANCELLED

Sign In or Register to comment.