Advertisement
Zuhairy_Harry

Firebase Message

Aug 21st, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. package com.example.esihat_application;
  2.  
  3. import android.app.Notification;
  4. import android.app.NotificationChannel;
  5. import android.app.NotificationManager;
  6.  
  7. import androidx.annotation.NonNull;
  8. import androidx.core.app.NotificationManagerCompat;
  9.  
  10. import com.google.firebase.messaging.FirebaseMessagingService;
  11. import com.google.firebase.messaging.RemoteMessage;
  12.  
  13. public class PushNotificationService extends FirebaseMessagingService {
  14.     @Override
  15.     public void onMessageReceived(@NonNull RemoteMessage message) {
  16.         super.onMessageReceived(message);
  17.         String title = message.getNotification().getTitle();
  18.         String body = message.getNotification().getBody();
  19.         final String CHANNEL_ID = "HEADS_UP_NOTIFICATIONS";
  20.         if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
  21.             NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "MyNotification", NotificationManager.IMPORTANCE_HIGH);
  22.             getSystemService(NotificationManager.class).createNotificationChannel(channel);
  23.             Notification.Builder notification = new Notification.Builder(this, CHANNEL_ID)
  24.                     .setContentTitle(title)
  25.                     .setContentText(body)
  26.                     .setSmallIcon(R.drawable.upload)
  27.                     .setAutoCancel(true);
  28.             NotificationManagerCompat.from(this).notify(1, notification.build());
  29.         }
  30.     }
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. <service android:name=".PushNotificationService"
  63.             android:exported="false">
  64.             <intent-filter>
  65.                 <action android:name="com.google.firebase.MESSAGING_EVENT"></action>
  66.             </intent-filter>
  67.  
  68.         </service>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement