【问题标题】:Implementing Android Notifications Programmatically in Firebase在 Firebase 中以编程方式实现 Android 通知
【发布时间】:2016-12-21 10:59:06
【问题描述】:

在没有后端的android中发送通知,我们必须在android studio中编写这些代码行:

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Intent intentViewPost = new Intent(PostsActivity.this,BlogPostsView.class);
PendingIntent pendingIntent = PendingIntent.getActivity(PostsActivity.this,(int) System.currentTimeMillis(), intentViewPost,0);

Notification notification = new Notification.Builder(getBaseContext())
        .setSmallIcon(R.mipmap.ic_app_logo)
        .setContentTitle(getResources().getString(R.string.app_name))
        .setContentText(postTitle)
        .setContentIntent(pendingIntent)
        .build();

manager.notify(111,notification);

如何在不使用控制台的情况下在 Firebase 中做同样的事情。

【问题讨论】:

    标签: android firebase firebase-notifications


    【解决方案1】:

    向特定设备发送消息

    要将消息发送到特定设备,请将 设置为特定应用实例的注册令牌

    curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>"  -X POST -d '{ "data": { "score": "5x1","time": "15:10"},"to" : "<registration token>"}' https://fcm.googleapis.com/fcm/send
    

    向主题发送消息

    这里的主题是:/topics/foo-bar

    curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>"  -X POST -d '{ "to": "/topics/foo-bar","data": { "message": "This is a Firebase Cloud Messaging Topic Message!"}}' https://fcm.googleapis.com/fcm/send
    

    向设备组发送消息

    向设备组发送消息与向单个设备发送消息非常相似。将 to 参数设置为设备组的唯一通知键

    curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>"  -X POST -d '{"to": "<aUniqueKey>","data": {"hello": "This is a Firebase Cloud Messaging Device Group Message!"}}' https://fcm.googleapis.com/fcm/send
    

    有关更多信息,请查看这些链接。

    【讨论】:

    • 这不能回答我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-09
    • 2012-12-03
    • 1970-01-01
    • 2011-11-12
    • 2013-10-16
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多