How to store firebase push notification in sqlite when app in background, foreground & closed state

I want to store the firebase push notification into sqlite when the app in any state like app is closed/background/foreground. How can i do this? Is it possible to do this?

Best Answer

  • MohanasundharamMohanasundharam ✭✭✭
    edited March 27 Accepted Answer
    public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);
            Log.Debug(TAG, "Notification Message Body: " + getBody);
            SendNotification(getBody, message.Data);
        }
    
        public override void HandleIntent(Intent p0)// this method will fire when the app in background and closed state
        {
            base.HandleIntent(p0);
            if (p0.Extras != null)
            {
                foreach (var key in p0.Extras.KeySet())
                {
                    var value = p0.Extras.GetString(key);
                    Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
                    if(key== "gcm.notification.title")
                    {
                        Log.Debug("Delay Notification Title", "" + value);
                        getBGTitle = value;//declared local variable
                    }
                    else if(key== "gcm.notification.body")
                    {
                        Log.Debug("Delay Notification Body", "" + value);
                        getBGBody = value;//declared local variable
            insertData(getBGTitle,getBGBody)//call method for store SQLite Insert
                    }
                }
            }
    }
    

Answers

  • HarshitaHarshita INMember ✭✭✭✭

    @Mohanasundharam aram
    You want to store what? the notification body?
    what exactly you want?

  • MohanasundharamMohanasundharam Member ✭✭✭

    I want to store Notification Title and Body

  • jezhjezh Member, Xamarin Team Xamurai

    Have you resolved this problem?

  • MohanasundharamMohanasundharam Member ✭✭✭

    yes. i resolved

  • jezhjezh Member, Xamarin Team Xamurai

    Congrats. Could you please share the solution so that others can get help from your case?

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello all

    @jezh yes good idea :smile:
    thanks to @Mohanasundharam

  • MohanasundharamMohanasundharam Member ✭✭✭
    edited March 27 Accepted Answer
    public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);
            Log.Debug(TAG, "Notification Message Body: " + getBody);
            SendNotification(getBody, message.Data);
        }
    
        public override void HandleIntent(Intent p0)// this method will fire when the app in background and closed state
        {
            base.HandleIntent(p0);
            if (p0.Extras != null)
            {
                foreach (var key in p0.Extras.KeySet())
                {
                    var value = p0.Extras.GetString(key);
                    Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
                    if(key== "gcm.notification.title")
                    {
                        Log.Debug("Delay Notification Title", "" + value);
                        getBGTitle = value;//declared local variable
                    }
                    else if(key== "gcm.notification.body")
                    {
                        Log.Debug("Delay Notification Body", "" + value);
                        getBGBody = value;//declared local variable
            insertData(getBGTitle,getBGBody)//call method for store SQLite Insert
                    }
                }
            }
    }
    
  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭
  • MohanasundharamMohanasundharam Member ✭✭✭

    Don't say thanks, it's my pleasure

Sign In or Register to comment.