Can we speed up setting notifications with the Notifications ANE by District?

113 Views Asked by At

I created an app that uses locale notifications. In order to set the notifications, a call is made to the backend, and a list of notifications to set is returned. I created a loop that goes through this list, and set the notifications one by one. I noticed it almost takes a second to set a notification. This is the function I call, when setting the notification:

public function sendNotification(title:String, body:String, delay:int, id:int, tickerText:String, data:String, alertAction:String = "") : void
    {
        if (Notifications.isSupported)
        {
            Notifications.service.notify(
                new NotificationBuilder()
                .setId(id)
                .setDelay( delay )
                .setAlert( tickerText )
                .setTitle( title )
                .setSound("sound/trigger")
                .enableVibration(false)
                .setCount(1)
                .setBody( body )
                .setPayload( data )
                .build()
            );
        }
    }

Is it possible to speed this up? Perhaps with a batch?

1

There are 1 best solutions below

1
On

Try this :

NotificationManager mNotificationManager =
                    (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

public void createSimpleNotification(Context context) {
        if (Build.VERSION.SDK_INT < 16)
            return;
        Intent resultIntent = null;
            resultIntent = new Intent(context, LauncherActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(SplashActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPending = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        Bundle bundle = new Bundle();
        bundle.putString(Constants.DATA, "Your data");
        resultIntent.putExtra(Constants.DATA, bundle);
        Notification.Builder mBuilder = new Notification.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher) // notification icon
                .setContentTitle("Title") // main title of the notification
                .setStyle(new Notification.BigTextStyle().bigText("Hello, how are you"))
                .setAutoCancel(true)
                .setContentText("Hello everyone") // notification text
                .setContentIntent(resultPending); // notification intent
        mNotificationManager.notify(1, mBuilder.build());
    }

Hope it will help you :)