Skip to content Skip to sidebar Skip to footer

Android Push Notification In Ionic

I am developing mobile app using ionic framework.I have Successfully implemented push notification.When I click on the notification I want it should go on particular page.How will

Solution 1:

notification you receive on client side has parameter foreground associated. It's value will be false when you come to application from clicking notification. So this is how you can perform specific action:

onNotification: function(notification) {
                  if(notification.foreground == false){
                    //add your logic here to navigate to other page
                  }
                }

Solution 2:

I resolve a similar situation some days ago. I've an app with articles list and article details. When there is a new article the server send a notification than include the article id in the playload.

When the app receive the notification, i save it in the localStorage and when the user click on the notification, with the resume event i can read this localStorage item and change the state of the app and show the article controller view for this article id.

I haven't used the ionPush library, i used the Cordova PushPlugin because i have a custom push notification server.

When the app received the notification:

$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
   if (ionic.Platform.isAndroid() && notification.event == 'message') {
        var newsid=notification.payload.newsid;
        if (typeof newsid != 'undefined') {
            // save the newsid to read it later in the resume event$window.localStorage.setItem('goafterpush',newsid);
        }
    }
});

And the resume event:

$ionicPlatform.on("resume",function(event){
     // read the newsid saved previously when received the notificationvar goafterpush=$window.localStorage.getItem('goafterpush');
     if (goafterpush) {
         $window.localStorage.removeItem('goafterpush');
         $state.go('app.newsdetail',{id:goafterpush});
     }
});

I hope this code can help you.

Solution 3:

I've this working for Android and iOS, in python I've set payload with the state name and Id parameter

payload = {"$state":"state.name", "$stateParams": "{\"id\": \""+time()+"\"}"}

Then I include it with all the other message stuff

"payload": payload

This should happen inside your $msg array, and that's it, when the user clicks the notification your app opens and goes to the defined state using the provided parameter.

Post a Comment for "Android Push Notification In Ionic"