6

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

enter image description here

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.

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
Phil
  • 4,029
  • 9
  • 62
  • 107
  • Could you go though [diagnosis guidelines](https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-push-notification-fixer/) and if nothing helps update the post with what is still happening? – Nikita R. Sep 09 '16 at 17:18
  • @NikitaG. - thank you for the link I absolutely will do. Will post back what I find – Phil Sep 09 '16 at 18:11
  • which device are you using ? – Diego Giorgini Sep 10 '16 at 19:31
  • @DiegoGiorgini. LG G2 – Phil Sep 11 '16 at 01:04
  • I just read the the first link mentioned in your question and I noted that azure notification-hub is quite different from FCM. This seems like a problem with azure and I am not competent on this, sorry. – Diego Giorgini Sep 11 '16 at 02:23
  • @NikitaG ive gone through the tutorial and everything is set up correctly. Registrations are working etc, but still no push from signed apk only. – Phil Sep 11 '16 at 14:12
  • It's still not clear whether the problem is on the PNS side or on Azure side. Could you try to [send a test push from command line](https://developers.google.com/web/fundamentals/getting-started/push-notifications/step-07?hl=en) without even using Azure code? If it works, then you'll need to dig into your NH registrations (but that's unlikely since it works for unsigned app). If the test push doesn't work, then there's something with the FCM configuration -- either the key is associated with a different app or notifications are disabled somehow on the phone or something else. – Nikita R. Sep 11 '16 at 16:57
  • @NikitaG. - I've followed the instructions to send a test push from command line. I'm getting the message that I've added to my post above which looks like a success message, however I get no push on my device. – Phil Sep 12 '16 at 15:21
  • @NikitaG - if you have time for chat, please send me invite. I'll be here all day (until 5 EST). Could REALLY use your help in determining why these aren't coming through. – Phil Sep 12 '16 at 15:30
  • @Phil, I know more about Notification Hubs then about Android/FCM, so unfortunately I wont' be able to help much as we've narrowed the problem down to something with outside of Azure. I would suggest to post on the corresponding Google group (and like to this question to provide everything you've learned so far). Their developers actively monitor the official forum and will hopefully be able to help you. – Nikita R. Sep 13 '16 at 06:53
  • @NikitaG, what Google group? Can you provide link to where you are suggesting I post? – Phil Sep 13 '16 at 19:53
  • @NikitaG - no one else gave as much help as you did. I want to give you the bounty on this question, but in order to do so I need some answer from you posted. – Phil Sep 19 '16 at 14:44
  • @Phil, posted a wrap up of our conversation in the comments. Glad you could make it work eventually. Did you figure it out by yourself trying or did you post somewhere else? – Nikita R. Sep 19 '16 at 17:35
  • @NikitaG. - figured it out by myself. Created a test project and it worked with signed APK, so I knew I had something wrong in my code. Went through line by line and then I saw the missing "public" modifier. – Phil Sep 19 '16 at 17:42

2 Answers2

3

After days of trying to figure this out, turns out my MyHandler class, which is the class responsible for handling pushes that come through, was not declared as public.

After changing the class to public, push now works on build and signed apks.

Would love someone to explain why this would only cause a problem when the app was installed from apk file though because that part has me stumped.

Phil
  • 4,029
  • 9
  • 62
  • 107
1

One important method to follow in these kind of issues if first to try to understand whether the problem is on the Notification Hubs side or on the PNS (FCM in this case) side.

One way to do it is to first go through the ANH diagnosis guidelines. If the issue is still not resolved, it may be helpful to try to push a message directly through the PNS to see whether that works or not. (In case of FCM, you can send a test push from the command line.)

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
  • 1
    thanks for all of your help figuring this out. Turns out I was missing the "public" modifier on my push handler class, but I would never have found it without your help eliminating other possibilities. – Phil Sep 19 '16 at 17:41
  • Glad you've figured it out. These things seem simple when you've already solved them, but are extremely hard to find. Great job! – Nikita R. Sep 19 '16 at 17:50