How do I pass push data from a GCMListenerService to the Pushwoosh Unity plugin?

Answered

Comments

1 comment

  • Avatar
    James

    In case anyone is interested, I got in touch with Pushwoosh support and found out that you can use the NotificationServiceExtension class to manually handle pushes. I created the service when constructing and then used it to handle any of my Pushwoosh data objects.

    public class GCMListenerRouterService extends GcmListenerService
    {
        NotificationServiceExtension service;
    
        public GCMListenerRouterService()
        {
            super();
            service = new NotificationServiceExtension();
        }
    
        private void dispatchMessage(String component, Bundle data)
        {
            Intent intent = new Intent();
            intent.putExtras(data);
            intent.setAction("com.google.android.c2dm.intent.RECEIVE");
            intent.setComponent(new ComponentName(getPackageName(), component));
    
            GcmReceiver.startWakefulService(getApplicationContext(), intent);
        }
    
        @Override
        public void onMessageReceived(String from, Bundle data)
        {
            // Base GCM listener service removes this extra before calling onMessageReceived
            // Need to set it again to pass intent to another service
            data.putString("from", from);
    
            String origin = data.getString("origin");
            if (origin != null && origin.equals("something"))
            {
                //Filter push to relevant handler here.
            }
            else
            {
                //Handle with Pushwoosh.
                service.handleMessage(data);
            }
        }
    }
    

Please sign in to leave a comment.