microsoft / msopentech-tools-for-intellij

Plugin for easy and fast development to enable developers of Android Apps to connect to Office 365 services and Azure Mobile Services, and developers of Java middleware to connect to Azure compute services
Apache License 2.0
28 stars 34 forks source link

Incorrect Hub Registration #170

Closed BeatriceOltean closed 9 years ago

BeatriceOltean commented 9 years ago

The AzureServicesActivity has this code in it: NotificationHub notificationHub = NotificationHubsHelper.getNotificationHub(this); notificationHub.register("GCM_REGISTRATION_ID”); Calling getNotificationHub kicks off an async task (inside NotificationsManager) which handles registering with GCM and getting the registration ID. We can’t call notificationHub.register here because we won’t necessarily have the ID back yet. More so we’re just passing in “GCM_REGISTRATION_ID” instead of an actual ID. I’d suggest altering the NotificationHubsHelper class so that it implements the onRegistered method and has a static reference to the instance of the NotificationHub object it can use to pull out the registration ID. You can see an example of this in a gist here: https://gist.github.com/ChrisRisner/796fb9d1c6ade285f489

leotilli commented 9 years ago

Fixed on Jan 20th (https://github.com/MSOpenTech/msopentech-tools-for-intellij/commit/8cfbd728316a0051ad6c5224c53bf732f48cbdfa)

And merged on Jan 28th (https://github.com/MSOpenTech/msopentech-tools-for-intellij/pull/113)

kasturiswain commented 9 years ago

Azure Service Activity has the following code in it. String hubName = context.getString(R.string.nh_name_activity_azure_services); String connStr = context.getString(R.string.nh_conn_str_activity_azure_services);

            NotificationHub hub = new NotificationHub(hubName, connStr, context);
            hub.register(gcmRegistrationId);
leotilli commented 9 years ago

Yes, and its part of the onRegistered event handler, so it's the expected behavior.

public static class NotificationHubsHelper extends NotificationsHandler {
        @Override
        public void onRegistered(Context context, String gcmRegistrationId) {
            try {
                String hubName = context.getString(R.string.nh_name_activity_azure_services);
                String connStr = context.getString(R.string.nh_conn_str_activity_azure_services);

                NotificationHub hub = new NotificationHub(hubName, connStr, context);
                hub.register(gcmRegistrationId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onUnregistered(Context context, String gcmRegistrationId) {
            try {
                String hubName = context.getString(R.string.nh_name_activity_azure_services);
                String connStr = context.getString(R.string.nh_conn_str_activity_azure_services);

                NotificationHub hub = new NotificationHub(hubName, connStr, context);
                hub.unregister();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onReceive(Context context, Bundle bundle) {
            super.onReceive(context, bundle);
            //YOU CAN OVERRIDE THE DEFAULT IMPLEMENTATION HERE
        }
    }
babumuralidharan commented 9 years ago

Closing this since the template code has been corrected.