I am trying to implement a GCMListenerService as we have two systems in our game that use GCM. I have been able the setup the listener service and I can output push data from each platform. I am confused by the following snippet of the documentation;

if (TextUtils.equals(from, getString(R.string.PUSHWOOSH_PROJECT_ID))) {
    dispatchMessage(PushGcmIntentService.class.getName(), data);
}
else if (TextUtils.equals(from, getString(R.string.PRIVATE_PROJECT_ID))) {
    dispatchMessage(PrivateGCMListenerService.class.getName(), data);
}

I am using the Unity plugin (5.5.3) and I cannot find references to these classes. Thus I am guessing they are sample code, but I am unable to find any documentation that accepts Bundle objects to process the push data.

What class/function do I need to pass the data to? What package is it in? Do I need to include any dependencies?

asked 17 Jan, 09:17
LKWD%20JamesD's gravatar image

LKWD JamesD
216

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);
        }
    }
}
permanent link
answered 22 Jan, 14:47
LKWD%20JamesD's gravatar image

LKWD JamesD
216

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×446
×445
×21
×3

question asked: 17 Jan, 09:17

question was seen: 73 times

last updated: 22 Jan, 14:47