Commit fb5998d9 authored by Simon MacDonald's avatar Simon MacDonald
Browse files
Merge branch 'master' of https://github.com/pjalbuquerque/phonegap-plugin-push into pjalbuquerque-master

Conflicts:
	src/android/com/adobe/phonegap/push/GCMIntentService.java
parents 33970e4c b6226a36
Loading
Loading
Loading
Loading
+1 −1
Changes for example/server/pushGCM.rb: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -4,6 +4,6 @@ GCM.host = 'https://android.googleapis.com/gcm/send'
GCM.format = :json
GCM.key = "API_KEY_GOES_HERE"
destination = ["REGISTRATION_ID_GOES_HERE"]
data = {:message => "PhoneGap Build rocks!", :msgcnt => "1", :soundname => "beep.wav"}
data = {:message => "PhoneGap Build rocks!", :msgcnt => "1", :soundname => "beep.wav", :group => 1, :stacking => "There %n% notifications",}

GCM.send_notification( destination, data)
+48 −1
Changes for src/android/com/adobe/phonegap/push/GCMIntentService.java: 48 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -27,13 +27,26 @@ import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.text.Html;

import com.google.android.gcm.GCMBaseIntentService;

import java.util.ArrayList;

@SuppressLint("NewApi")
public class GCMIntentService extends GCMBaseIntentService {

    private static final String LOG_TAG = "PushPlugin_GCMIntentService";
    private static ArrayList messageList = new ArrayList();

    public void setNotification(String message){

        if(message == ""){
            messageList.clear();
        }else{
            messageList.add(message);
        }
    }

    public GCMIntentService() {
        super("GCMIntentService");
@@ -234,8 +247,42 @@ public class GCMIntentService extends GCMBaseIntentService {

    private void setNotificationMessage(Bundle extras, NotificationCompat.Builder mBuilder) {
        NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();

        String message = getMessageText(extras);

        int group = 0;
        try {
            group = Integer.parseInt(extras.getString("group"));
            if(group == 1){
                setNotification(message);

                Integer sizeList = messageList.size();
                if(sizeList > 1){
                    String sizeListMessage = sizeList.toString();
                    String stacking = sizeList+" more";
                    if(extras.getString("stacking") != null){
                        stacking = extras.getString("stacking");
                        stacking = stacking.replace("%n%", sizeListMessage);
                    }
                    NotificationCompat.InboxStyle notificationInbox = new NotificationCompat.InboxStyle()
                        .setBigContentTitle(extras.getString("title"))
                        .setSummaryText(stacking);

                    for(Object noticationMensage : messageList){
                       notificationInbox.addLine(Html.fromHtml(noticationMensage.toString()));
                    }

                    mBuilder.setStyle(notificationInbox);
                    mBuilder.setLargeIcon(null);
                }
            }
        }
        catch(NumberFormatException e) {
            Log.e(LOG_TAG, "Number format exception - Error parsing Group: " + e.getMessage());
        }
        catch(Exception e) {
            Log.e(LOG_TAG, "Number format exception - Error parsing Group" + e.getMessage());
        }

        if (message != null) {
            mBuilder.setContentText(message);

+2 −0
Changes for src/android/com/adobe/phonegap/push/PushHandlerActivity.java: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ public class PushHandlerActivity extends Activity
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		GCMIntentService gcm = new GCMIntentService();
		gcm.setNotification("");
		super.onCreate(savedInstanceState);
		Log.v(LOG_TAG, "onCreate");