简体   繁体   English

在没有 Firebase 控制台的情况下向所有设备发送推送通知

[英]Sending Push Notifications to all devices without Firebase Console

I'm making an app for work that's meant to be a portal for patrons using Java in Android Studio.我正在制作一个工作应用程序,旨在成为在 Android Studio 中使用 Java 的顾客的门户。 I've set up Firebase Cloud Messaging, Authentication, and a Realtime database to store users.我已经设置了 Firebase 云消息传递、身份验证和实时数据库来存储用户。 I can send out push notifications easily from the Cloud Console, but I was wondering if there was a way to send push notifications to all devices without using the console?我可以轻松地从 Cloud Console 发送推送通知,但我想知道是否有一种方法可以在不使用控制台的情况下向所有设备发送推送通知?

My reasoning is that I don't want someone in HR accidentally deleting a user, but I would like them to be able to send out push notifications for situations such as closings.我的理由是,我不希望 HR 中的某个人意外删除用户,但我希望他们能够在关闭等情况下发送推送通知。 Is there any way to do that, either through a remote push to all devices, or a restricted version of the console so that changes can't be made?有没有办法做到这一点,无论是通过远程推送到所有设备,还是控制台的受限版本,以便无法进行更改? I'm pretty new to this, so forgive me if this is a simple question.我对此很陌生,所以如果这是一个简单的问题,请原谅我。

You can send notifications to all devices, provided all devices are subscribed to a topic.您可以向所有设备发送通知,前提是所有设备都订阅了一个主题。

You can create a php file that is responsible for sending the information to firebase using the api token.您可以创建一个php文件,负责使用api 令牌将信息发送到 firebase

If it has served you, I would appreciate your approval of my comment, regards.如果它对您有用,我将不胜感激您批准我的评论,问候。

Notification.php :通知.php :

    $token = 'test'; // Topic or Token devices here
    $url = "https://fcm.googleapis.com/fcm/send";

    // api key
    $serverKey = ''; // add api key here

    $notification = array('title' => 'Welcome StackOverFlow' , 'body' => 'Testing body', 'sound' => 'default', 'badge' => '1');
    $data = array('extraInfo'=> 'DomingoMG');
    $arrayToSend = array('to' => $token, 'notification' => $notification, 'priority'=>'high', 'data'=> $data);
    $json = json_encode($arrayToSend);
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key='. $serverKey;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);

    //Send the request
    $response = curl_exec($ch);
    //Close request
    if ($response === FALSE) {
     die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);

You can use the Firebase Admin SDK from a backend or other machine that you fully control.您可以从后端或您完全控制的其他机器使用Firebase Admin SDK It has an API for sending messages to devices where you have collected their device ID tokens.它有一个API,用于向您收集了设备 ID 令牌的设备 发送消息

There is no additional console or GUI for sending messages - you will have to write code if the console doesn't do what you want.没有用于发送消息的额外控制台或 GUI - 如果控制台没有执行您想要的操作,您将不得不编写代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在没有 Firebase Cloud Messaging (FCM) 的情况下向所有安装了我的应用程序的设备发送推送通知? - is it possible to make push notifications to all devices which had installed my application without Firebase Cloud Messaging (FCM)? 使用FCM,SQL,Java将推送通知发送到多个设备 - Sending push notifications to multiple devices using FCM, SQL, java 使用Java将推送通知发送到UrbanAirship测试设备 - Sending push notifications to UrbanAirship test devices using java Firebase:在所有设备上向用户发送推送通知 - Firebase: Send push notification to user on all their devices aws推送多个设备的通知 - aws push notifications for multiple devices GCM推送通知未传递到设备 - GCM Push Notifications are not delivered to devices 如何向所有在Firebase中注册的用户发送推送通知? - How to send push notifications to all the users who have registered in Firebase? Firebase Java Server 向所有设备发送推送通知 - Firebase Java Server to send push notification to all devices 通过公共代码将通知推送到各种设备 - Push notifications to various devices through a common code Android推送通知未使用Firebase云消息传递或任何其他类似服务 - Android Push Notifications Without using Firebase Cloud Messaging or any other similar service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM