【发布时间】:2017-01-17 17:09:27
【问题描述】:
我已关注 Sending push notifications to Android with Azure Notification Hubs tutorial,使用 Azure 通知中心将通知推送到我的 Android 应用程序中。
之前,我使用另一个教程使用带有 Azure 通知中心的 Google 云消息传递服务来执行此操作,但是当我将应用程序从 Android Studio 发送到我的设备时,我只能获得推送通知。当我构建一个签名的 APK 并将其安装在我的设备上时,没有推送通知通过。
在昨天尝试了一整天让它工作(禁用 ProGuard,尝试不同的 API 密钥等)后,我决定今天早上重新开始。那时我意识到,当用户从 Cloud Console 中单击 GCM 时,Google 现在会将用户定向到 Firebase Cloud Messaging。所以...我已经使用上述教程和 Google FCM 在我的应用中实现了推送通知。
效果很好....但同样,当我创建一个签名的 APK 并将其安装在我的设备上而不是从 Android Studio 将应用程序发送到我的设备时,我没有收到任何推送通知。 Azure 显示推送发送成功,但没有通过。
在我的推送处理程序中,我有一个到控制台的日志,如下面的 onReceive 方法所示。当我从 Android Studio 运行应用程序时,这会被很好地调用,并且推送会按应有的方式进行。但是,当我创建签名的 apk 并从中运行时,不会调用 onReceive 方法,也不会通过任何推送。
@Override
public void onReceive(Context context, Bundle bundle) {
Log.d("TAG","TRIGGERED");
ctx = context;
String nhMessage = bundle.getString("message");
String nhTitle = bundle.containsKey("title") ? bundle.getString("title") : "Title";
String nhBadge = bundle.containsKey("badge") ? bundle.getString("badge") : null ;
sendNotification(nhMessage,nhTitle,nhBadge);
if (Main.isVisible) { Main.mainActivity.ToastNotify(nhMessage); }
}
有人请帮助我。我错过了什么?????? 是因为我直接安装APK吗?是否必须从 Google Play 下载?除此之外,我看不出它会是什么。
更新
按照 Nikita G 的建议,我关注了instructions to send a test push from the command line using cURL。
我得到的响应如下(看起来像一条成功消息)但是我的设备上没有推送。
{"multicast_id":6722521883082447284,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1473693614087201%06fb35f0f9fd7ecd"}]}
我的 cURL 请求看起来像这样,就像教程显示的那样。
curl --header "Authorization: key=XXXXXXXXXXXX" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"fs...Tw:APA...SzXha\"]}"
更新
我刚刚注意到,这不仅仅是在我使用 SIGNED APK 时。在 Android Studio 中,如果我使用 Build APK 选项生成 APK
然后使用位于 myappfolder/app/build/output/apk/ 的 app-debug.apk 文件进行安装,推送通知仍然不起作用。只有当我使用 Run 选项从 Android Studio 发送到我的设备时,它们才有效。
【问题讨论】:
-
你能不能去diagnosis guidelines,如果没有什么可以帮助更新帖子,了解仍在发生的事情?
-
@NikitaG。 - 感谢您提供我绝对会做的链接。会发回我发现的内容
-
你用的是什么设备?
-
@DiegoGiorgini。 LG G2
-
我刚刚阅读了您问题中提到的第一个链接,我注意到 azure notification-hub 与 FCM 完全不同。这似乎是 azure 的问题,抱歉,我对此无能为力。
标签: android azure firebase firebase-cloud-messaging azure-notificationhub