0

I have created android application and I send notification to a particular person with firebase server. Help me please.

My code is:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG="MyMessageservice";
    RemoteMessage remoteMessage;
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage){
        String title=remoteMessage.getNotification().getTitle();
        String message=remoteMessage.getNotification().getBody();
        String lick_action=remoteMessage.getNotification().getClickAction();
        Intent intent=new Intent(click_action);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri notificattionSound= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(this);
        notificationbuilder.setContentTitle(title);
        notificationbuilder.setContentText(message);
        notificationbuilder.setAutoCancel(true);
        notificationbuilder.setSound(notificattionSound);
        notificationbuilder.setSmallIcon(R.drawable.ic_launcher);
        notificationbuilder.setContentIntent(pendingIntent);
        notificationbuilder.setAutoCancel(true);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationbuilder.build());
    }
KENdi
  • 7,205
  • 2
  • 14
  • 26
Anbu
  • 17
  • 1
  • 9

1 Answers1

0

If you want to send a notification to a specific device, i suggest you OneSignal. It is very simple to implement and it's free.

The benefit of this solution is not that you can send notification only to a specific user you can also send to a group of users and you don't need 3rd party servers to accomplish it.

Please take a look a this video.

Hope it helps.

Alex Mamo
  • 91,677
  • 13
  • 105
  • 138