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

package com.ntels.onecable.admin.common.gcm;


import com.ntels.onecable.admin.common.util.Dlog;
import com.ntels.onecable.admin.common.util.Util;

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;

/**
 * <pre>
 * 1. ClassName :   FcmBroadcastReceiver
 * 2. FileName  :   FcmBroadcastReceiver.java
 * 3. Package   :   com.ntels.onecable.common.gcm.service
 * 4. Date      :   2016-12-05
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class FcmBroadcastReceiver extends WakefulBroadcastReceiver {

    Util mUtil = 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("FcmBroadcastReceiver.java | onReceive", "|" + key + mUtil.null2string(value) + "|");
            }
            Dlog.i("FcmBroadcastReceiver.java | onReceive", "|" + "=================" + "|");

            // Explicitly specify that GcmIntentService1 will handle the intent.
            ComponentName comp = new ComponentName(context.getPackageName(), FcmIntentService.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();
        }
    }
}
