Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.smartnotices;
- import android.util.Log;
- import com.example.smartnotices.R;
- import com.google.firebase.messaging.FirebaseMessagingService;
- import com.google.firebase.messaging.RemoteMessage;
- public class MyFireBaseMessagingService extends FirebaseMessagingService {
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- Log.e("ISSERVICESTARTED????", "no idea right now");
- super.onMessageReceived(remoteMessage);
- if(remoteMessage.getNotification() != null){
- String title = remoteMessage.getNotification().getTitle();
- String body = remoteMessage.getNotification().getBody();
- NotificationHelper.displayNotification(getApplicationContext(),title,body);
- }
- }
- }
- package com.example.smartnotices;
- import android.app.NotificationManager;
- import android.content.Context;
- import android.support.v4.app.NotificationCompat;
- import android.support.v4.app.NotificationManagerCompat;
- import com.example.smartnotices.R;
- public class NotificationHelper {
- public static void displayNotification(Context context, String title, String body){
- NotificationCompat.Builder mBuilder =
- new NotificationCompat.Builder(context, "notification_channel")
- .setSmallIcon(R.mipmap.ic_launcher)
- .setContentText(body)
- .setContentTitle(title)
- .setPriority(NotificationCompat.PRIORITY_DEFAULT);
- NotificationManagerCompat mNotificationMgr = NotificationManagerCompat.from(context);
- mNotificationMgr.notify(0 /* ID of notification */, mBuilder.build());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement