Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onHandleIntent(Intent intent) {
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- String resultString = null;
- String regID = null;
- try {
- InstanceID instanceID = InstanceID.getInstance(this);
- String token = instanceID.getToken(NotificationSettings.SenderId,
- GoogleCloudMessaging.INSTANCE_ID_SCOPE);
- Log.i(TAG, "Got GCM Registration Token: " + token);
- // Storing the registration id that indicates whether the generated token has been
- // sent to your server. If it is not stored, send the token to your server,
- // otherwise your server should have already received the token.
- /* Tu mi chyba hub = new....*/
- if ((regID=sharedPreferences.getString("registrationID", null)) == null) {
- NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
- NotificationSettings.HubListenConnectionString, this);
- Log.i(TAG, "Attempting to register with NH using token : " + token);
- regID = hub.register(token).getRegistrationId();
- // If you want to use tags...
- // Refer to : https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-routing-tag-expressions/
- // regID = hub.register(token, "tag1,tag2").getRegistrationId();
- resultString = "Registered Successfully - RegId : " + regID;
- Log.i(TAG, resultString);
- sharedPreferences.edit().putString("registrationID", regID ).apply();
- } else {
- /* tu mi chyba regID = hub.register()....*/
- resultString = "Previously Registered Successfully - RegId : " + regID;
- }
- } catch (Exception e) {
- Log.e(TAG, resultString="Failed to complete token refresh", e);
- // If an exception happens while fetching the new token or updating our registration data
- // on a third-party server, this ensures that we'll attempt the update at a later time.
- }
- // Notify UI that registration has completed.
- if (MainActivity.isVisible) {
- MainActivity.mainActivity.ToastNotify(resultString);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement