我的项目中有来自azure的继承NotificationHandler
的类。在更新我的项目之前一切正常(接收器没有任何变化)。现在,每次安装应用程序时,NotificationHandler
始终触发并发送空通知。我认为我的问题与this question类似。
这是源代码
<receiver android:name="com.microsoft.windowsazure.notifications.NotificationsBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="_mypackage" />
</intent-filter>
</receiver>
任何帮助将不胜感激
答案 0 :(得分:4)
I had the exact same problem, and found the solution here: Weird push message received on app start
Everytime my application was reinstalled my BroadcastReceiver for push mesages received an Intent, and I was handling it like a normal push notification (which led to the display of an empty notification to the user). Apparently google started sending this intents that have the same intent filter as the regular push messages in order to handle refresh of push tokens. If you look at google's documentation for implementing push clients on Android, you will see that it now recommends us to stop creating out BroadcastReceivers, and use googles GCMReceiver (see https://developers.google.com/cloud-messaging/android/client)
Since I was not going to reimplement my push client at that time, I had to filter the intents and figure out which ones were generated by the GCM and which ones were sent by my push server. On both cases I could always get a field called "from" inside the intent's extras, so I used it to filter. All intents launched by Google had "google.com/iid" as this field, and the other notifications had my project number on it (example: "from": "42352342352423")
String from = extras.getString("from");
if (!"google.com/iid".equals(from)) {
// create notification
}
I hope that helps you