0

I need display notifications when my server return specific values. I have a service running on android and taskschedule running every time sending request to server, when the server return positive value i need display message on celular display, similar receive message of whatsapp (display icon and notification on display). Anyone have a sample?

I trying this:

PendingIntent resultPendingIntent = PendingIntent.getActivity(
    this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);

But my application is running as a service.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

Please use Using Service to run background and create notification

private void processStartNotification() {
        // Do something. For example, fetch fresh data from backend to create a rich notification?

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle("Scheduled Notification")
                .setAutoCancel(true)
                .setColor(getResources().getColor(R.color.colorAccent))
                .setContentText("This notification has been triggered by Notification Service")
                .setSmallIcon(R.drawable.notification_icon);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,
                NOTIFICATION_ID,
                new Intent(this, NotificationActivity.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
        builder.setDeleteIntent(NotificationEventReceiver.getDeleteIntent(this));

        final NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(NOTIFICATION_ID, builder.build());
    }
Community
  • 1
  • 1
Ramit
  • 416
  • 3
  • 8