package com.dieam.reactnativepushnotification.modules;

import android.content.Intent;
import android.os.Bundle;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;

import java.util.List;

import com.google.android.gms.gcm.GcmListenerService;

public class RNPushNotificationListenerService extends GcmListenerService {

    @Override
    public void onMessageReceived(String from, Bundle bundle) {
        sendNotification(bundle);
    }

    private void sendNotification(Bundle bundle) {

        Boolean isRunning = isApplicationRunning();
        
        Intent intent = new Intent("RNPushNotificationReceiveNotification");
        bundle.putBoolean("foreground", isRunning);
        intent.putExtra("notification", bundle);
        sendBroadcast(intent);

        if (!isRunning) {
            new RNPushNotificationHelper(getApplication(), this).sendNotification(bundle);
        }
    }

    private boolean isApplicationRunning() {
        ActivityManager activityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
            if (processInfo.processName.equals(getApplication().getPackageName())) {
                if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    for (String d: processInfo.pkgList) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
@@ -280,16 +280,76 @@
 rvice;%0A%0A
+import org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0A
 public c
@@ -507,33 +507,627 @@
     
-sendNotification(bundle);
+JSONObject data = getPushData(bundle.getString(%22data%22));%0A        if (data != null) %7B%0A            if (!bundle.containsKey(%22message%22)) %7B%0A                bundle.putString(%22message%22, data.optString(%22alert%22, %22Notification received%22));%0A            %7D%0A            if (!bundle.containsKey(%22title%22)) %7B%0A                bundle.putString(%22title%22, data.optString(%22title%22, null));%0A            %7D%0A        %7D%0A%0A        sendNotification(bundle);%0A    %7D%0A%0A    private JSONObject getPushData(String dataString) %7B%0A        try %7B%0A            return new JSONObject(dataString);%0A        %7D catch (JSONException e) %7B%0A            return null;%0A        %7D
 %0A   

Make it compatible with Parse push by @frantic https://github.com/zo0r/react-native-push-notification/pull/22