SHARE
TWEET

Untitled

a guest Jun 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.smartnotices;
  2.  
  3. import android.util.Log;
  4.  
  5. import com.example.smartnotices.R;
  6. import com.google.firebase.messaging.FirebaseMessagingService;
  7. import com.google.firebase.messaging.RemoteMessage;
  8.  
  9. public class MyFireBaseMessagingService extends FirebaseMessagingService {
  10.  
  11.     @Override
  12.     public void onMessageReceived(RemoteMessage remoteMessage) {
  13.         Log.e("ISSERVICESTARTED????", "no idea right now");
  14.         super.onMessageReceived(remoteMessage);
  15.         if(remoteMessage.getNotification() != null){
  16.             String title = remoteMessage.getNotification().getTitle();
  17.             String body = remoteMessage.getNotification().getBody();
  18.             NotificationHelper.displayNotification(getApplicationContext(),title,body);
  19.         }
  20.     }
  21. }
  22.      
  23. package com.example.smartnotices;
  24.  
  25. import android.app.NotificationManager;
  26. import android.content.Context;
  27. import android.support.v4.app.NotificationCompat;
  28. import android.support.v4.app.NotificationManagerCompat;
  29.  
  30. import com.example.smartnotices.R;
  31.  
  32. public class NotificationHelper {
  33.     public  static void displayNotification(Context context, String title, String body){
  34.         NotificationCompat.Builder mBuilder =
  35.                 new NotificationCompat.Builder(context, "notification_channel")
  36.                         .setSmallIcon(R.mipmap.ic_launcher)
  37.                         .setContentText(body)
  38.                         .setContentTitle(title)
  39.                         .setPriority(NotificationCompat.PRIORITY_DEFAULT);
  40.         NotificationManagerCompat mNotificationMgr = NotificationManagerCompat.from(context);
  41.         mNotificationMgr.notify(0 /* ID of notification */, mBuilder.build());
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top