Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.esihat_application;
- import android.app.Notification;
- import android.app.NotificationChannel;
- import android.app.NotificationManager;
- import androidx.annotation.NonNull;
- import androidx.core.app.NotificationManagerCompat;
- import com.google.firebase.messaging.FirebaseMessagingService;
- import com.google.firebase.messaging.RemoteMessage;
- public class PushNotificationService extends FirebaseMessagingService {
- @Override
- public void onMessageReceived(@NonNull RemoteMessage message) {
- super.onMessageReceived(message);
- String title = message.getNotification().getTitle();
- String body = message.getNotification().getBody();
- final String CHANNEL_ID = "HEADS_UP_NOTIFICATIONS";
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
- NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "MyNotification", NotificationManager.IMPORTANCE_HIGH);
- getSystemService(NotificationManager.class).createNotificationChannel(channel);
- Notification.Builder notification = new Notification.Builder(this, CHANNEL_ID)
- .setContentTitle(title)
- .setContentText(body)
- .setSmallIcon(R.drawable.upload)
- .setAutoCancel(true);
- NotificationManagerCompat.from(this).notify(1, notification.build());
- }
- }
- }
- <service android:name=".PushNotificationService"
- android:exported="false">
- <intent-filter>
- <action android:name="com.google.firebase.MESSAGING_EVENT"></action>
- </intent-filter>
- </service>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement