Ali_Waris
Ali_Waris

Reputation: 2382

Azure notifications working on mobile data and not on Wi-Fi

I am implementing push notifications functionality in my android application using Azure Notification Hub. Everything seems to be working fine; I have just one issue.

I am able to get push notifications on my device only if I am connected to internet with my mobile data; once I switch my mobile data off and connects through Wi-Fi, I am unable to receive any push notification message.

I am narrowing my search horizon to the fact that there is some issue with the very first registration. It allows only that mode (in my case, Mobile data) to receive any push messages.

For registration, I am using the following code:

    NotificationsManager.handleNotifications(this, SENDER_ID, NotificationsReceiver.class);
    gcm = GoogleCloudMessaging.getInstance(this);
    hub = new NotificationHub(HubName, HubListenConnectionString, this);
    registerWithNotificationHubs();
.
.
.
private void registerWithNotificationHubs() {
        new AsyncTask() {
            @Override
            protected Object doInBackground(Object... params) {
                try {
                    String regid = gcm.register(SENDER_ID);
                    DialogNotify("Registered Successfully", "RegId : " +
                            hub.register(regid).getRegistrationId());
                } catch (Exception e) {
                    DialogNotify("Exception", e.getMessage());
                    return e;
                }
                return null;
            }
        }.execute(null, null, null);
    }

Upvotes: 0

Views: 171

Answers (1)

Ali_Waris
Ali_Waris

Reputation: 2382

Eureka...!!!! :) It was an issue with Google Play Services. It was getting connected when mobile data was turned on, but no connection was made to Wi-Fi. The culprit was IPv6. Just disable IPv6 and everything works like a charm.

To check whether Google Play Services is working properly or not; dial this code from your phone's dialer : * # * # 426 # * # * and verify whether it is connected or not.

NOTE: You can get many apps in Play Store to disable IPv6 when on Wi-Fi connection. I'm using IPv6 Tool app to disable IPv6.

Upvotes: 1

Related Questions