I've followed Sending push notifications to Android with Azure Notification Hubs tutorial to implement Push notifications into my Android app using the Azure Notification Hub.
Previously, I used another tutorial to do this using the Google Cloud Messaging service with Azure Notification Hub, however I was only able to get Push notifications when I sent my app to my device from Android Studio. When I built a signed APK and installed that on my device, no push notifications came through.
After trying all day yesterday to get it to work (disabling ProGuard, trying different API keys etc) I decided to start fresh this morning. That is when I realized that Google now directs users to the Firebase Cloud Messaging when they click on GCM from the Cloud Console. So...I've implemented the Push Notifications into my app using the above tutorial and Google FCM.
It works great....but again, when I create a signed APK and install that on my device rather than sending the app to my device from Android Studio, I get no push notifications. Azure shows that the push was sent successfully, but nothing comes through.
In my push handler, I have a log to the console as seen below in the onReceive method. This gets called fine when I run the app from Android Studio, and the push comes through as it should. But when I create signed apk and run from that, the onReceive method does not get called and no push comes through.
@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); }
}
Someone please help me. What am I missing????? Is it because I'm installing the APK directly? Does it HAVE to be downloaded from Google Play? Other than that, I don't see what it could be.
UPDATE
As per Nikita G's suggestion, I've followed the instructions to send a test push from the command line using cURL.
The response I get back is the following (which looks like a success message) however I get no Push on my device.
{"multicast_id":6722521883082447284,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1473693614087201%06fb35f0f9fd7ecd"}]}
My cURL request looks like this, just like the tutorial shows.
curl --header "Authorization: key=XXXXXXXXXXXX" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"fs...Tw:APA...SzXha\"]}"
UPDATE
I just noticed that it is not just when I use a SIGNED APK. In Android Studio, if I generate a APK using the Build APK option
and then install using the app-debug.apk file located at myappfolder/app/build/output/apk/, the Push Notifications still do not work. they ONLY work if I send to my device from Android Studio using the Run option.