/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.common.gcm.service;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.WakefulBroadcastReceiver;

import com.ntels.kneet.v3.common.util.Dlog;
import com.ntels.kneet.v3.common.util.Util;
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {

    Util util = new Util();
    @Override public void onReceive(Context context, Intent intent) {

        try {
            Dlog.e(context.getPackageName(), "GCMBroadcastReceiver onReceive");
            Bundle bundle = intent.getExtras();
            for ( String key : bundle.keySet() ) {
                Object value = bundle.get(key);
                Dlog.i("GcmBroadcastReceiver.java | onReceive", "|" + key + util.null2string(value) + "|");
            }
            Dlog.i("GcmBroadcastReceiver.java | onReceive", "|" + "=================" + "|");

            // Explicitly specify that GcmIntentService will handle the intent.
            ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
            // Start the service, keeping the device awake while it is launching.
            startWakefulService(context, intent.setComponent(comp));
            setResultCode(Activity.RESULT_OK);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
