FCM Notification using Android Studio

前端 未结 2 847
渐次进展
渐次进展 2021-01-27 03:26

I managed to send notification message from PHP file and send to mobile phone using Firebase Cloud Messaging (FCM).

Once the user click on the notification message on mo

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-27 03:32

    check this.

    private void sendNotification(String messageBody)
    {
     Intent intent = new Intent(this, MainActivity.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Firebase Push Notification")
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    
       NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    
     notificationManager.notify(0, notificationBuilder.build());
    }
    

提交回复
热议问题