0
votes

I'm using MobileFirst Studio Platform, for send notifications push, in the App i receive the notification, but if sent multiple notifications to my app, this only sample last notification sending.

I need show all the notifications in list in the bar notifications the device, each that i receive the notification.

This is code for function the adapter for send notification:

var applicationId="ElUniversalAppAndroid";

function sendNotification(notificationText, tag,url){
var notification = {};

notification.message = {};
notification.message.alert = notificationText;

var tags = tag.split(",");

notification.target = {};
notification.target.tagNames = tags;

// set notification properties for GCM
notification.settings = {};
notification.settings.gcm = {};
notification.settings.gcm.payload = {"url":url};
notification.settings.gcm.sound = 'sinsajo.mp3';

var delay=WL.Server.sendMessage(applicationId, notification);
WL.Logger.error("Notificacion enviada exitosamente " + JSON.stringify(notification));
return { result: "Notification sent"}; 
}

and I am follow example in the IBM Knowledges and support the IBM.

I am using MobileFirst Platform Studio 7.0 and Android Native Push Notifications Tags Based.

I find the answer

[Other answer same][1]

but I don't working in MobileFirst Platform Studio

Next the code the class GCMIntentService:

package com.test.eluniversal.tagsuniversal;
import java.util.Iterator;
import java.util.Queue;
import org.json.JSONObject;
import com.worklight.nativeandroid.common.WLUtils;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;

public class GCMIntentService extends
  com.worklight.wlclient.push.GCMIntentService {

  private NotificationObject getNotification(Intent intent) {
    NotificationObject notificationObject=new NotificationObject();
    com.worklight.wlclient.push.GCMIntentService.Message message=
    intent.getParcelableExtra("message");
    notificationObject.setId((int)System.currentTimeMillis());
    String title= "TagsUniversal";
    JSONObject alertJsonObject=message.getProps();
    String alert=alertJsonObject.optString("alert",null);
    notificationObject.setTitle(title);
    notificationObject.setAlert(alert);
    JSONObject payload = message.getPayload();
    String url = payload.optString("url", null);
    notificationObject.setUrl(url);
    return notificationObject;
 }

 @Override
 public void notify(Context context, String alert, int badge, String
  sound,Intent intent) {
   createNotification(context, alert, getNotificationTitle(context),
    alert, badge, sound, intent);
 }

 @Override
 public void notify(Context context, String tickerText) {
   createNotification(context, tickerText,
   getNotificationTitle(context),tickerText, 0, "1", null);
 }

 private void createNotification(Context context, String ticker,
                    String title, String msg, int badge,String sound,
                    Intent intent) {
   int icon = -1;
   long when = System.currentTimeMillis();

   try {
     icon = WLUtils.getResourceId(getApplicationContext(), "drawable",
      "push");
   } catch (Exception e) {
     // ERROR: add icon resource
   }
   NotificationObject notificationObject=getNotification(intent);
   NotificationCompat.Builder mBuilder = new 
   NotificationCompat.Builder(
this).setSmallIcon(icon).setContentTitle(notificationObject.getTitle())
    .setContentText(msg);

mBuilder.setAutoCancel(true);
mBuilder.setTicker(ticker);
mBuilder.setNumber(badge);
mBuilder.setWhen(when);

Intent viewIntent = new Intent(this, ActivityPrincipal.class);
viewIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0,
    viewIntent, 0);

mBuilder.setContentIntent(viewPendingIntent);

Notification myNotification = mBuilder.build();

NotificationManagerCompat nm = NotificationManagerCompat.from(this);
nm.notify(notificationObject.getId(), myNotification);

// play notification sound, vibrate, etc...

}
}

and using next class model:

package com.test.eluniversal.tagsuniversal;

public class NotificationObject {
  private int id=0;
  private String title=null;
  private String alert=null;
  private String sound=null;
  private String url=null;
  private String icon=null;

public NotificationObject(){

}

public NotificationObject(int id,String title, String alert, String url){
  this.id=id;
  this.title=title;
  this.alert=alert;
  this.url=url;
}

public int getId() {
  return id;
}

public void setId( int id ) {
  this.id = id;
}

public String getTitle() {
  return title;
}

public void setTitle( String title ) {
  this.title = title;
}

public String getAlert() {
  return alert;
}

public void setAlert( String alert ) {
  this.alert = alert;
}

public String getSound() {
  return sound;
}

public void setSound( String sound ) {
  this.sound = sound;
}

public String getUrl() {
  return url;
}

public void setUrl( String url ) {
  this.url = url;
}

public String getIcon() {
  return icon;
}

public void setIcon( String icon ) {
  this.icon = icon;
}

}

and the nex is Manifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<permission android:name="com.test.eluniversal.tagsuniversal.permission.C2D_MESSAGE" android:protectionLevel="signature"/>

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>

<uses-permission android:name="com.test.eluniversal.tagsuniversal.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:launchMode="singleTask">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity
        android:name=".ActivityPrincipal"
        android:label="@string/app_name"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.test.eluniversal.tagsuniversal.tagsUniversal.NOTIFICATION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <service android:name="com.test.eluniversal.tagsuniversal.GCMIntentService" />
    <receiver android:name="com.worklight.wlclient.push.WLBroadcastReceiver"
              android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            <category android:name="com.test.eluniversal.tagsuniversal"/>
        </intent-filter>
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.test.eluniversal.tagsuniversal" />
        </intent-filter>
    </receiver>
</application>

and next message the error:

"Your manifest is not allowed to work with push. Android Manifest Error: Missing intent service in manifest: com.worklight.wlclient.push.GCMIntentService

1

1 Answers

0
votes

Worklight/MFP does not supply this functionality built-in.

That said, you can override the default implementation and do this on your own.
Review the following blog post by Yoel Nunez which explains how to do such override and implements similar functionality: InboxStyle Notifications in Android.