智能工厂.apk(点击下载) / JPushReceiver.java


package cn.jiguang.cordova.push;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.JThirdPlatFormInterface;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JPushReceiver extends BroadcastReceiver {
    private static final List<String> IGNORED_EXTRAS_KEYS = Arrays.asList(JPushInterface.EXTRA_TITLE, JPushInterface.EXTRA_MESSAGE, JPushInterface.EXTRA_APP_KEY, JPushInterface.EXTRA_NOTIFICATION_TITLE, "key_show_entity", JThirdPlatFormInterface.KEY_PLATFORM);

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(JPushInterface.ACTION_REGISTRATION_ID)) {
            JPushPlugin.transmitReceiveRegistrationId(intent.getStringExtra(JPushInterface.EXTRA_REGISTRATION_ID));
        } else if (action.equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) {
            handlingMessageReceive(intent);
        } else if (action.equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
            handlingNotificationReceive(context, intent);
        } else if (action.equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
            handlingNotificationOpen(context, intent);
        }
    }

    private void handlingMessageReceive(Intent intent) {
        JPushPlugin.transmitMessageReceive(intent.getStringExtra(JPushInterface.EXTRA_MESSAGE), getNotificationExtras(intent));
    }

    private void handlingNotificationOpen(Context context, Intent intent) {
        String stringExtra = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
        JPushPlugin.openNotificationTitle = stringExtra;
        String stringExtra2 = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
        JPushPlugin.openNotificationAlert = stringExtra2;
        Map<String, Object> notificationExtras = getNotificationExtras(intent);
        JPushPlugin.openNotificationExtras = notificationExtras;
        JPushPlugin.transmitNotificationOpen(stringExtra, stringExtra2, notificationExtras);
        Intent launchIntentForPackage = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        if (launchIntentForPackage != null) {
            launchIntentForPackage.addCategory("android.intent.category.LAUNCHER");
            launchIntentForPackage.setFlags(805306368);
            context.startActivity(launchIntentForPackage);
        }
    }

    private void handlingNotificationReceive(Context context, Intent intent) {
        String stringExtra = intent.getStringExtra(JPushInterface.EXTRA_NOTIFICATION_TITLE);
        JPushPlugin.notificationTitle = stringExtra;
        String stringExtra2 = intent.getStringExtra(JPushInterface.EXTRA_ALERT);
        JPushPlugin.notificationAlert = stringExtra2;
        Map<String, Object> notificationExtras = getNotificationExtras(intent);
        JPushPlugin.notificationExtras = notificationExtras;
        JPushPlugin.transmitNotificationReceive(stringExtra, stringExtra2, notificationExtras);
    }

    private Map<String, Object> getNotificationExtras(Intent intent) {
        HashMap hashMap = new HashMap();
        for (String str : intent.getExtras().keySet()) {
            if (!IGNORED_EXTRAS_KEYS.contains(str)) {
                if (str.equals(JPushInterface.EXTRA_NOTIFICATION_ID)) {
                    hashMap.put(str, Integer.valueOf(intent.getIntExtra(str, 0)));
                } else {
                    hashMap.put(str, intent.getStringExtra(str));
                }
            }
        }
        return hashMap;
    }
}