Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • PhoneGap-How to handle Push notification when application is resumed?

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 372
    Comment on it

    Hello friends,


    As we have seen, cordova push plugin only provides access to notification action when we click on notification from status bar, but if we want to perform that action without clicking on notification we have to add some extra code.



    1. First of all open GCMIntentService.java file under com.plugin.gcm from eclipse project
    2. you will find the below method:
    public void createNotification(Context context, Bundle extras)
    3. You will find below lines:
    mBuilder = new NotificationCompat.Builder(context)
                    .setDefaults(Notification.DEFAULT_ALL)
                    .setSmallIcon(context.getApplicationInfo().icon)
                    .setWhen(System.currentTimeMillis())
                    .setContentTitle("Notification")
                    .setContentText(jsonObject.getString("alert"))
                    .setTicker(extras.getString("title"))
                    .setContentIntent(contentIntent);
    
    4. At the end of the above object add the following property
     .setAutoCancel(true); 
    5. Now implement Following code in javascript side in NotificationGCM(e) function: case 'message':
         if ( e.foreground ){
    
         }else{  
                //The user touched a notification in the notification tray.
                //when app in background and to the perticular page.
         }
    
         navigator.notification.alert(e.msg);
    
    break;
    

    Here e.msg is the data or message which is returned by the GCM.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: