【问题标题】:Android push notifications separating production & development分离生产和开发的 Android 推送通知
【发布时间】:2017-02-01 01:25:18
【问题描述】:

我一直在翻阅文档,但似乎找不到我的问题的答案。与 Apple 将生产和开发 APN 分开并允许测试不同,Android 是否有类似的功能?我们有生产中的应用程序,但需要在内部测试推送通知而不影响我们的用户群。通过制作两个 Firebase 项目是实现这一目标的唯一方法吗?

编辑: 由于我们的一些测试是通过 beta 测试进行的,因此并非所有测试设备都在眼前。 谢谢你

【问题讨论】:

  • 嗨。你见过这个post吗? :)

标签: android firebase push-notification firebase-cloud-messaging


【解决方案1】:

这很简单。获取要测试通知的设备/模拟器。 运行您的应用程序。通过以下方式获取该设备的 firebase 密钥:

 String firebaseKey = FirebaseInstanceId.getInstance().getToken();

现在,在您的服务器中使用此代码仅向该设备发送通知。

  function sendSingleNotification($id, $message){

$fields = array(
    'to' => $id,
    'data' => $message,
);

$url = 'https://fcm.googleapis.com/fcm/send';

$headers = array(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);
// Open connection

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
    die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-16
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    相关资源
    最近更新 更多