如何在Android应用程序中调用fire base console并发送到特定用户app中的通知(device-fire base-device)

时间:2017-05-04 08:36:40

标签: android firebase push-notification notifications

我创建了android应用程序,并通过firebase服务器向特定的人发送通知。请帮帮我。

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());
    }

1 个答案:

答案 0 :(得分:0)

如果您想向特定设备发送通知,我建议您OneSignal。它实现起来非常简单,而且是免费的。

此解决方案的好处并不在于您只能向特定用户发送通知,您也可以向一组用户发送通知,而您无需第三方服务器即可完成此操作。

请看一下video

希望它有所帮助。