morinel / gcmpush

Titanium Module for Android Push
Apache License 2.0
57 stars 35 forks source link

More than one notification showing setting probably doesn't work #33

Open kerberosargos opened 8 years ago

kerberosargos commented 8 years ago

Hi Yes I know last 3 issue tickets are mine. I need to know this is a bug or my wrong setting error? Please answer me because I have no time for publishing my app :(

My sample logcat report as below. One more notification received from my remote server to android phone, every notification data appear on logcat like below.

But when I would like to show my notifications using grouping or separately, group setting doesn't work. Every notification is lost when new one came.

D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [527,568086] Push notification received
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568086] Message key: "from" value: "xxxxxxx"
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568086] Message key: "view" value: "viewMain"
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [1,568087] Message key: "sound" value: "my.mp3"
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568087] Message key: "title" value: "Sample title 1"
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568087] Message key: "message" value: "Sample message 1"
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568087] Message key: "collapse_key" value: "do_not_collapse"

E/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [81,568168] Invalid setting ledOn, should be Integer
E/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568168] Invalid setting ledOff, should be Integer
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [2,568170] Title: Sample message 1
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568170] Message: Sample message 1
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568170] Ticker: null
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568170] Creating notification...
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [8,568178] Group: News
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568178] LocalOnly: false
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568178] Priority: 2
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568178] bigText: true
D/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [2,568180] Sound specified in notification
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568180] Sound buzzer.mp3
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568180] Vibrate: true
I/GCMIntentService(28427): (IntentService[GCMIntentService--2]) [0,568180] Insistent: false
D/TiAPI   (28427):  [TiPush] onReceive Push callback = {"inBackground":true,"data":{"sound":"my.mp3","title":"Sample title 1","message":"Sample title 1 ","from":"xxxxxxxxx","collapse_key":"do_not_collapse","view":"viewMain"}}
I

My Appceleretor settings as below

notificationSettings : {
                sound : 'bounce.mp3', //> Place sound file in platform/android/res/raw/mysound.mp3
                smallIcon : 'notification.png', //> Place icon in platform/android/res/drawable/notification_icon.png
                largeIcon : 'appicon.png', //> Same
                vibrate : true, //> Whether the phone should vibrate
                insistent : false, //> Whether the notification should be insistent
                group : 'News', //> Name of group to group similar notifications together
                localOnly : false, //> Whether this notification should be bridged to other devices
                priority : +2, //> Notification priority, from -2 to +2
                bigText : true,
                //> Add LED flashing
                ledOn : 200,
                ledOff : 300,
                backgroundOnly : false
            }
morinel commented 8 years ago

What happens if you remove any settings you don't need, like ledOn/ledOff, bigTest, backgroundOnly, insistent, etc?

kerberosargos commented 8 years ago

Firstly thank you for quick answer but nothing change. Logcat report as below;

D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [38,177] Push notification received
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,178] Message key: "from" value: "xxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,178] Message key: "view" value: "favorites"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,179] Message key: "sound" value: "bounce.mp3"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,179] Message key: "title" value: "xxxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,179] Message key: "message" value: "xxxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,180] Message key: "collapse_key" value: "do_not_collapse"
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [66,246] Title: xxxx
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,247] Message: xxxxx
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,247] Ticker: null
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,247] Creating notification...
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [12,259] Group: News
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,260] LocalOnly: false
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,260] Priority: 2
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,260] bigText: true
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [13,273] Sound specified in notification
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,273] Sound bounce.mp3
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,274] Vibrate: true
I/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,275] Insistent: false
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [7,282] Push notification received
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,283] Message key: "from" value: "xxxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,283] Message key: "view" value: "favorites"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,283] Message key: "sound" value: "bounce.mp3"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [1,284] Message key: "title" value: "xxxxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,284] Message key: "message" value: "xxxxx"
D/GCMIntentService(16052): (IntentService[GCMIntentService--1]) [0,284] Message key: "collapse_key" value: "do_not_collapse"

Last settings

notificationSettings : {
                sound : 'bounce.mp3', //> Place sound file in platform/android/res/raw/mysound.mp3
                smallIcon : 'notification.png', //> Place icon in platform/android/res/drawable/notification_icon.png
                largeIcon : 'appicon.png', //> Same
                vibrate : true, //> Whether the phone should vibrate
                insistent : false, //> Whether the notification should be insistent
                group : 'News', //> Name of group to group similar notifications together
                localOnly : false, //> Whether this notification should be bridged to other devices
                priority : +2, //> Notification priority, from -2 to +2
                bigText : true,

            }
morinel commented 8 years ago

Try without these settings:

                insistent : false, //> Whether the notification should be insistent
                group : 'News', //> Name of group to group similar notifications together
                localOnly : false, //> Whether this notification should be bridged to other devices
                priority : +2, //> Notification priority, from -2 to +2
                bigText : true
kerberosargos commented 8 years ago

I have sent twice time notification from my remote server but they did not appear on my device.

Appcelerator settings:

sound : 'bounce.mp3', //> Place sound file in platform/android/res/raw/mysound.mp3
                smallIcon : 'notification.png', //> Place icon in platform/android/res/drawable/notification_icon.png
                largeIcon : 'appicon.png', //> Same
                vibrate : true, //> Whether the phone should vibrate

Remote server settings:

                    'message'   => $ArrPushMessage["Message"],
                    'title'     => $ArrPushMessage["Title"],

Notification son result

Array ( [multicast_id] => 4.9523621355218E+18 [success] => 1 [failure] => 0 [canonical_ids] => 0 [results] => Array ( [0] => Array ( [message_id] => 0:1458493214513473%2d713a4ef9fd7ecd ) ) ) Array ( [multicast_id] => 8.963309427397E+18 [success] => 1 [failure] => 0 [canonical_ids] => 0 [results] => Array ( [0] => Array ( [message_id] => 0:1458493214608687%2d713a4ef9fd7ecd ) ) )

kerberosargos commented 8 years ago

Hi again. I wrote this issue onto Stack Overflow after your suggestions. Link is here

Rachit Solanki wrote a comment about this issue. I have looked your code source again (GCMIntentService.java) May be Rachit Solanki's suggest can fix problem.

Thank you in advance

kerberosargos commented 8 years ago

If you can build new pre-released version of your module, I can tray.

kerberosargos commented 8 years ago

Hi again. I found sample as below

((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
                .notify(getId(), notificationBuilder.build());

I think if you can change code as below at GCMIntentService.java

((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(1, notification);

May be this issue fix.

kerberosargos commented 8 years ago

Hi again, I made some changes according to my needs at GCMIntentService.java after that I build project. I am using now on my project. Thank you for interest and may be code as below can help you. Cheers.

New settings type for ledOn and ledOff must be string as below

ledOn : '200',
ledOff : '300'
/**
 * Copyright 2015  Jeroen van Vianen
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.vanvianen.android.gcm;

import java.util.concurrent.atomic.AtomicInteger;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.gson.Gson;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.util.TiRHelper;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;

public class GCMIntentService extends GCMBaseIntentService {

    private static final String LCAT = "GCMIntentService";

    private static final String UNREGISTER_EVENT = "unregister";

    private static final String DEFAULT_TITLE_KEY = "title";
    private static final String DEFAULT_MESSAGE_KEY = "message";
    private static final String DEFAULT_TICKER_KEY = "ticker";
    private final static AtomicInteger counter = new AtomicInteger(0);

    public GCMIntentService() {
        super("");
    }

    @Override
    public void onRegistered(Context context, String registrationId) {
        Log.d(LCAT, "Registered: " + registrationId);

        GCMModule.getInstance().sendSuccess(registrationId);
    }

    @Override
    public void onUnregistered(Context context, String registrationId) {
        Log.d(LCAT, "Unregistered");

        GCMModule.getInstance().fireEvent(UNREGISTER_EVENT, new HashMap<String, Object>());
    }

    private int getId() {
         return counter.incrementAndGet();
    }

    public int tryParse(Object obj) {
      Integer retVal;
      try {
        retVal = Integer.parseInt((String) obj);
      } catch (NumberFormatException nfe) {
        retVal = 0; // or null if that is your preference
      }
      return retVal;
    }

    private int getResource(String type, String name) {
        int icon = 0;
        if (name != null) {
            /* Remove extension from icon */
            int index = name.lastIndexOf(".");
            if (index > 0) {
                name = name.substring(0, index);
            }
            try {
                icon = TiRHelper.getApplicationResource(type + "." + name);
            } catch (TiRHelper.ResourceNotFoundException ex) {
                Log.e(LCAT, type + "." + name + " not found; make sure it's in platform/android/res/" + type);
            }
        }

        return icon;
    }

    @Override
    @SuppressWarnings("unchecked")
    protected void onMessage(Context context, Intent intent) {
        Log.d(LCAT, "Push notification received");

        boolean isTopic = false;

        HashMap<String, Object> data = new HashMap<String, Object>();
        for (String key : intent.getExtras().keySet()) {
            String value = intent.getExtras().getString(key);
            Log.d(LCAT, "Message key: \"" + key + "\" value: \"" + value + "\"");

            if (key.equals("from") && value != null && value.startsWith("/topics/")) {
                isTopic = true;
            }

            String eventKey = key.startsWith("data.") ? key.substring(5) : key;
            data.put(eventKey, intent.getExtras().getString(key));

            if (value.startsWith("{")) {
                Log.d(LCAT, "Parsing JSON string...");
                try {
                    JSONObject json = new JSONObject(value);

                    Iterator<String> keys = json.keys();
                    while (keys.hasNext()) {
                        String jKey = keys.next();
                        String jValue = json.getString(jKey);
                        Log.d(LCAT, "JSON key: \"" + jKey + "\" value: \"" + jValue + "\"");

                        data.put(jKey, jValue);
                    }
                }
                catch(JSONException e) {
                    Log.d(LCAT, "JSON error: " + e);
                }
            }
        }

        /* Store data to be retrieved when resuming app as a JSON object, serialized as a String, otherwise
         * Ti.App.Properties.getString(GCMModule.LAST_DATA) doesn't work. */
        JSONObject json = new JSONObject(data);
        TiApplication.getInstance().getAppProperties().setString(GCMModule.LAST_DATA, json.toString());

        /* Get settings from notification object */
        int smallIcon = 0;
        int largeIcon = 0;
        String sound = null;
        boolean vibrate = false;
        boolean insistent = false;
        String group = null;
        int notificationId = 1;
        boolean localOnly = true;
        int priority = 0;
        boolean bigText = false;

        int ledOn = 0;
        int ledOff = 0;

        String titleKey = DEFAULT_TITLE_KEY;
        String messageKey = DEFAULT_MESSAGE_KEY;
        String tickerKey = DEFAULT_TICKER_KEY;
        String title = null;
        String message = null;
        String ticker = null;

        boolean backgroundOnly = false;

        Map<String, Object> notificationSettings = new Gson().fromJson(TiApplication.getInstance().getAppProperties().getString(GCMModule.NOTIFICATION_SETTINGS, null), Map.class);
        if (notificationSettings != null) {
            if (notificationSettings.get("smallIcon") instanceof String) {
                smallIcon = getResource("drawable", (String) notificationSettings.get("smallIcon"));
            } else {
                Log.e(LCAT, "Invalid setting smallIcon, should be String");
            }

            if (notificationSettings.get("largeIcon") instanceof String) {
                largeIcon = getResource("drawable", (String) notificationSettings.get("largeIcon"));
            } else {
                Log.e(LCAT, "Invalid setting largeIcon, should be String");
            }

            if (notificationSettings.get("sound") != null) {
                if (notificationSettings.get("sound") instanceof String) {
                    sound = (String) notificationSettings.get("sound");
                } else {
                    Log.e(LCAT, "Invalid setting sound, should be String");
                }
            }

            if (notificationSettings.get("vibrate") != null) {
                if (notificationSettings.get("vibrate") instanceof Boolean) {
                    vibrate = (Boolean) notificationSettings.get("vibrate");
                } else {
                    Log.e(LCAT, "Invalid setting vibrate, should be Boolean");
                }
            }

              Log.i(LCAT, "vibrate: " + vibrate);

            if (notificationSettings.get("insistent") != null) {
                if (notificationSettings.get("insistent") instanceof Boolean) {
                    insistent = (Boolean) notificationSettings.get("insistent");
                } else {
                    Log.e(LCAT, "Invalid setting insistent, should be Boolean");
                }
            }

            if (notificationSettings.get("group") != null) {
                if (notificationSettings.get("group") instanceof String) {
                    group = (String) notificationSettings.get("group");
                } else {
                    Log.e(LCAT, "Invalid setting group, should be String");
                }
            }

            if (notificationSettings.get("localOnly") != null) {
                if (notificationSettings.get("localOnly") instanceof Boolean) {
                    localOnly = (Boolean) notificationSettings.get("localOnly");
                } else {
                    Log.e(LCAT, "Invalid setting localOnly, should be Boolean");
                }
            }

            if (notificationSettings.get("priority") != null) {
                if (notificationSettings.get("priority") instanceof Integer) {
                    priority = (Integer) notificationSettings.get("priority");
                } else if (notificationSettings.get("priority") instanceof Double) {
                    priority = ((Double) notificationSettings.get("priority")).intValue();
                } else {
                    Log.e(LCAT, "Invalid setting priority, should be an integer, between PRIORITY_MIN (" + NotificationCompat.PRIORITY_MIN + ") and PRIORITY_MAX (" + NotificationCompat.PRIORITY_MAX + ")");
                }
            }

            if (notificationSettings.get("bigText") != null) {
                if (notificationSettings.get("bigText") instanceof Boolean) {
                    bigText = (Boolean) notificationSettings.get("bigText");
                } else {
                    Log.e(LCAT, "Invalid setting bigText, should be Boolean");
                }
            }

            if (notificationSettings.get("titleKey") != null) {
                if (notificationSettings.get("titleKey") instanceof String) {
                    titleKey = (String) notificationSettings.get("titleKey");
                } else {
                    Log.e(LCAT, "Invalid setting titleKey, should be String");
                }
            }

            if (notificationSettings.get("messageKey") != null) {
                if (notificationSettings.get("messageKey") instanceof String) {
                    messageKey = (String) notificationSettings.get("messageKey");
                } else {
                    Log.e(LCAT, "Invalid setting messageKey, should be String");
                }
            }

            if (notificationSettings.get("tickerKey") != null) {
                if (notificationSettings.get("tickerKey") instanceof String) {
                    tickerKey = (String) notificationSettings.get("tickerKey");
                } else {
                    Log.e(LCAT, "Invalid setting tickerKey, should be String");
                }
            }

            if (notificationSettings.get("title") != null) {
                if (notificationSettings.get("title") instanceof String) {
                    title = (String) notificationSettings.get("title");
                } else {
                    Log.e(LCAT, "Invalid setting title, should be String");
                }
            }

            if (notificationSettings.get("message") != null) {
                if (notificationSettings.get("message") instanceof String) {
                    message = (String) notificationSettings.get("message");
                } else {
                    Log.e(LCAT, "Invalid setting message, should be String");
                }
            }

            if (notificationSettings.get("ticker") != null) {
                if (notificationSettings.get("ticker") instanceof String) {
                    ticker = (String) notificationSettings.get("ticker");
                } else {
                    Log.e(LCAT, "Invalid setting ticker, should be String");
                }
            }

            if (notificationSettings.get("ledOn") != null) {
                if (notificationSettings.get("ledOn") instanceof String) {
                    ledOn = tryParse(notificationSettings.get("ledOn"));
                    if (ledOn < 0) {
                        Log.e(LCAT, "Invalid setting ledOn, should be positive");
                        ledOn = 0;
                    }
                } else {
                    Log.e(LCAT, "Invalid setting ledOn, should be Integer");
                }
            }

            if (notificationSettings.get("ledOff") != null) {
                if (notificationSettings.get("ledOff") instanceof String) {
                    ledOff = tryParse(notificationSettings.get("ledOff"));
                    if (ledOff < 0) {
                        Log.e(LCAT, "Invalid setting ledOff, should be positive");
                        ledOff = 0;
                    }
                } else {
                    Log.e(LCAT, "Invalid setting ledOff, should be Integer");
                }
            }

            if (notificationSettings.get("backgroundOnly") != null) {
                if (notificationSettings.get("backgroundOnly") instanceof Boolean) {
                    backgroundOnly = (Boolean) notificationSettings.get("backgroundOnly");
                } else {
                    Log.e(LCAT, "Invalid setting backgroundOnly, should be Boolean");
                }
            }

        } else {
            Log.d(LCAT, "No notification settings found");
        }

        /* If icon not found, default to appicon */
        if (smallIcon == 0) {
            smallIcon = getResource("drawable", "appicon");
        }

        /* If large icon not found, default to icon */
        if (largeIcon == 0) {
            largeIcon = smallIcon;
        }

        /* Create intent to (re)start the app's root activity */
        String pkg = TiApplication.getInstance().getApplicationContext().getPackageName();
        Intent launcherIntent = TiApplication.getInstance().getApplicationContext().getPackageManager().getLaunchIntentForPackage(pkg);
        launcherIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        /* Grab notification content from data according to provided keys if not already set */
        if (title == null && titleKey != null) {
            title = (String) data.get(titleKey);
        }
        if (message == null && messageKey != null) {
            message = (String) data.get(messageKey);
        }
        if (ticker == null && tickerKey != null) {
            ticker = (String) data.get(tickerKey);
        }

        Log.i(LCAT, "Title: " + title);
        Log.i(LCAT, "Message: " + message);
        Log.i(LCAT, "Ticker: " + ticker);

        if (backgroundOnly && GCMModule.getInstance().isInForeground()) {
            Log.d(LCAT, "Notification received in foreground, no need for notification.");
            return;
        }

        if (message == null) {
            Log.d(LCAT, "Message received but no 'message' specified in push notification payload, so will make this silent");
        } else {
            Log.d(LCAT, "Creating notification...");

            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), largeIcon);
            if (bitmap == null) {
                Log.d(LCAT, "No large icon found");
            }

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                    .setContentTitle(title)
                    .setContentText(message)
                    .setTicker(ticker)
                    .setContentIntent(PendingIntent.getActivity(this, 0, launcherIntent, PendingIntent.FLAG_ONE_SHOT))
                    .setSmallIcon(smallIcon)
                    .setLargeIcon(bitmap);

            /* Name of group to group similar notifications together, can also be set in the push notification payload */
            if (data.get("group") != null) {
                group = (String) data.get("group");
            }
            if (group != null) {
                builder.setGroup(group);
            }
            Log.i(LCAT, "Group: " + group);

            /* Notification unique id, can also be set in the push notification payload */
            if (data.get("notificationId") != null) {
                notificationId = tryParse((String) data.get("notificationId"));
            }

            if(notificationId == 0)
            {
                notificationId = getId();
            }

            Log.i(LCAT, "notificationId: " + notificationId);

            /* Whether notification should be for this device only or bridged to other devices, can also be set in the push notification payload */
            if (data.get("localOnly") != null) {
                localOnly = Boolean.valueOf((String) data.get("localOnly"));
            }
            builder.setLocalOnly(localOnly);
            Log.i(LCAT, "LocalOnly: " + localOnly);

            /* Specify notification priority, can also be set in the push notification payload */
            if (data.get("priority") != null) {
                priority = Integer.parseInt((String) data.get("priority"));
            }
            if (priority >= NotificationCompat.PRIORITY_MIN && priority <= NotificationCompat.PRIORITY_MAX) {
                builder.setPriority(priority);
                Log.i(LCAT, "Priority: " + priority);
            } else {
                Log.e(LCAT, "Ignored invalid priority " + priority);
            }

            /* Specify whether bigtext should be used, can also be set in the push notification payload */
            if (data.get("bigText") != null) {
                bigText = Boolean.valueOf((String) data.get("bigText"));
            }
            if (bigText) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
            }
            Log.i(LCAT, "bigText: " + bigText);

            Notification notification = builder.build();

            /* Sound, can also be set in the push notification payload */
            if (data.get("sound") != null) {
                Log.d(LCAT, "Sound specified in notification");
                sound = (String) data.get("sound");
            }

            if ("default".equals(sound)) {
                Log.i(LCAT, "Sound: default sound");
                notification.defaults |= Notification.DEFAULT_SOUND;
            } else if (sound != null) {
                Log.i(LCAT, "Sound " + sound);
                notification.sound = Uri.parse("android.resource://" + pkg + "/" + getResource("raw", sound));
            }

            Log.i(LCAT, "Vibrate: " + vibrate);

            /* Vibrate, can also be set in the push notification payload */
            if (data.get("vibrate") != null) {
                vibrate = Boolean.valueOf((String) data.get("vibrate"));
            }
            if (vibrate) {
                notification.defaults |= Notification.DEFAULT_VIBRATE;
            }
            Log.i(LCAT, "Vibrate: " + vibrate);

            /* Insistent, can also be set in the push notification payload */
            if ("true".equals(data.get("insistent"))) {
                insistent = true;
            }
            if (insistent) {
                notification.flags |= Notification.FLAG_INSISTENT;
            }
            Log.i(LCAT, "Insistent: " + insistent);

            /* Specify LED flashing */
            if (ledOn > 0 || ledOff > 0) {
                notification.flags |= Notification.FLAG_SHOW_LIGHTS;
                if (ledOn > 0) {
                    notification.ledOnMS = ledOn;
                }
                if (ledOff > 0) {
                    notification.ledOffMS = ledOff;
                }
            } else {
                notification.defaults |= Notification.DEFAULT_LIGHTS;
            }

            Log.i(LCAT, "ledOn: " + ledOn);
            Log.i(LCAT, "ledOff: " + ledOff);

            notification.flags |= Notification.FLAG_AUTO_CANCEL;

            ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(notificationId, notification);
        }

        if (GCMModule.getInstance() != null) {
            if (isTopic) {
                GCMModule.getInstance().sendTopicMessage(data);
            } else {
                GCMModule.getInstance().sendMessage(data);
            }
        }
    }

    @Override
    public void onError(Context context, String errorId) {
        Log.e(LCAT, "Error: " + errorId);

        if (GCMModule.getInstance() != null) {
            GCMModule.getInstance().sendError(errorId);
        }
    }

    @Override
    public boolean onRecoverableError(Context context, String errorId) {
        Log.e(LCAT, "RecoverableError: " + errorId);

        if (GCMModule.getInstance() != null) {
            GCMModule.getInstance().sendError(errorId);
        }

        return true;
    }
}
ElSifi commented 8 years ago

@kerbooo How did it go with the (only one notification is appearing) problem ?

kerberosargos commented 8 years ago

I modified source codes as I need then I forked codes. If you need you can build your own with my forked codes. 4 Nis 2016 01:32 tarihinde "Mohamed ElSifi" notifications@github.com yazdı:

@kerbooo https://github.com/kerbooo How did it go with the (only one notification is appearing) problem ?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/morinel/gcmpush/issues/33#issuecomment-205068246

mcvendrell commented 8 years ago

Shit @kerbooo, 1 week searching for this solution and, when I found the solution you had it ready 2 months ago!!! This needs to be accepted ASAP

morinel commented 8 years ago

I just released version 1.5 which hopefully fixes the issue for you.