protected override void OnHandleIntent(Intent intent) { try { lock (locker) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken("783702026879", GoogleCloudMessaging.InstanceIdScope, null); Log.Info("AndroidTips", "GCM Registration Token: " + token); SendRegistrationToAppServer(token); Subscribe(token); // If receiving "Not Registered" failures when sending a notification // remove token and instanceId //instanceID.DeleteToken( token, GoogleCloudMessaging.InstanceIdScope ); //instanceID.DeleteInstanceID(); } } catch (Exception ex) { Log.Debug("AndroidTips", "Failed to get a registration token" + ex.Message); return; } }
// OnHandleIntent is invoked on a worker thread: protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); // Ensure that the request is atomic: lock (this) { // Request a registration token: var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken("YOUR_SENDER_ID", GoogleCloudMessaging.InstanceIdScope, null); // Log the registration token that was returned from GCM: Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); // Send to the app server (if it requires it): SendRegistrationToAppServer(token); // Subscribe to receive notifications: SubscribeToTopics(token, Topics); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token"); } }
protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { var instanceID = InstanceID.GetInstance(this); //instanceID.DeleteInstanceID(); //instanceID = InstanceID.GetInstance(this); string sSenderId = Joyces.Platform.AppContext.Instance.Platform.SenderId; var token = instanceID.GetToken(sSenderId, GoogleCloudMessaging.InstanceIdScope, null); Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); //SendRegistrationToAppServer(token); Joyces.Helpers.Settings.PushDeviceToken = token; //TODO::kolla varför den crashar här?! Subscribe(token); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token"); return; } }
public string GetToken() { var token = string.Empty; var thread = new System.Threading.Thread(() => { try { lock (locker) { var instanceID = InstanceID.GetInstance(MainActivity.AppMainContext); token = instanceID.GetToken( "912851590439", GoogleCloudMessaging.InstanceIdScope, null); //Subscrevendo if (!string.IsNullOrEmpty(token)) { Subscribe(token); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); } }); thread.Start(); thread.Join(1000); return(token); }
protected override void OnHandleIntent(Intent intent) { var sharedPreferences = PreferenceManager.GetDefaultSharedPreferences(this); try { lock (TAG) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken(GetString(Resource.String.gcm_defaultSenderId), GoogleCloudMessaging.InstanceIdScope, null); Log.Info(TAG, "GCM Registration Token: " + token); SendRegistrationToServer(token); SubscribeTopics(token); sharedPreferences.Edit().PutBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).Apply(); } } catch (Exception e) { Log.Debug(TAG, "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. sharedPreferences.Edit().PutBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).Apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. var registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.GetInstance(this).SendBroadcast(registrationComplete); }
protected override void OnHandleIntent(Intent intent) { try { Bundle extras = intent.Extras; lock (syncLock) { InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context); string token = instanceID.GetToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope, null); CrossPushNotification.PushNotificationListener.OnRegistered(token, DeviceType.Android); PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, token); System.Diagnostics.Debug.WriteLine(string.Format("{0} - Device registered, registration ID=" + token, Tag)); } }catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("{0} - Error :" + ex.Message, Tag)); CrossPushNotification.PushNotificationListener.OnError(string.Format("{0} - Register - " + ex.ToString(), Tag), DeviceType.Android); } // Intent registrationComplete = new Intent(PushNotificationKey.RegistrationComplete); // LocalBroadcastManager.GetInstance(Android.App.Application.Context).SendBroadcast(registrationComplete); }
// OnHandleIntent is invoked on a worker thread: protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetAuthToken"); //FirebaseApp.InitializeApp(this); // Ensure that the request is atomic: lock (this) { // Request a registration token: var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken("509579216493", GoogleCloudMessaging.InstanceIdScope, null); //Toast.MakeText(this, token, ToastLength.Short).Show(); // Log the registration token that was returned from GCM: Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); CurrentUser.PutDeviceToken(token); // Send to the app server (if it requires it): //SendRegistrationToAppServer(token); //FirebaseMessaging.Instance.SubscribeToTopic("global"); // Subscribe to receive notifications: SubscribeToTopics(token, Topics); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token", e.Message); } }
protected override void OnHandleIntent(Intent intent) { // Get the new token and send to the server var instanceID = InstanceID.GetInstance(Application.Context); var token = instanceID.GetToken(GCM_SENDER_ID, GoogleCloudMessaging.InstanceIdScope); var p = GetSharedPreferences("gcmsample", FileCreationMode.Private); var oldToken = p.GetString("gcm-token", ""); if (oldToken != token) { var pe = p.Edit(); pe.PutString("gcm-token", token); pe.Commit(); // TODO: You will want to send this token change to your server! // Fire the event for any UI subscribed to it TokenRefreshed?.Invoke(token); Android.Util.Log.Debug("GCM-SAMPLE", "OnTokenRefresh called"); } Android.Util.Log.Debug("GCM-SAMPLE", "Token: {0}", token); }
protected override void OnHandleIntent(Intent intent) { try { Log.Info(LogTag, "Calling InstanceID.GetToken"); lock (s_locker) { var instanceId = InstanceID.GetInstance(this); var token = instanceId.GetToken(Config.GcmNotificationKey, GoogleCloudMessaging.InstanceIdScope, null); Log.Info(LogTag, "GCM Reg token: " + token); var settings = new Settings(this); settings.gcmId = token; settings.commit(); // If we've already logged in, go ahead and register the device with the server. Otherwise, // it'll happen when we log in later. if (!settings.authToken.IsNullOrEmpty()) { Task.Run(() => Network.RegisterDevice(settings.authToken, Protocol.PushServiceType.Google, Settings.GetAndroidID(this), token).Wait()); } } } catch (Exception e) { Log.Error(LogTag, "Can't register GCM: " + e); } }
protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken("649212692032", GoogleCloudMessaging.InstanceIdScope, null); Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); SendRegistrationToAppServer(token); //Subscribe (token); // we are not using topics } } catch (Exception e) { var failureInfo = TraceHelper.ExceptionToString(e); Console.WriteLine("RegistrationIntentService::OnHandleIntent() Exception(): " + failureInfo); return; } }
public string GetToken() { var instance = InstanceID.GetInstance(Xamarin.Forms.Forms.Context); var token = instance.GetToken(Constants.GCMSenderId, GoogleCloudMessaging.InstanceIdScope); return(token); }
// static object locker = new object(); public Task <string> GetPushId() { return(Task.Factory.StartNew <string>(() => { var token = ""; try { if (IsPlayServicesAvailable()) { //lock (locker) //{ var instanceID = InstanceID.GetInstance(Forms.Context); token = instanceID.GetToken( CommonSettings.SenderID, GoogleCloudMessaging.InstanceIdScope, null); return token; //} } else { return ""; } } catch (Exception ex) { } return token; })); }
// OnHandleIntent is invoked on a worker thread: protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); // Ensure that the request is atomic: lock (this) { // Request a registration token: var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken(Constants.GCMSenderId, GoogleCloudMessaging.InstanceIdScope, null); // Log the registration token that was returned from GCM: Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); // Send to the app server (if it requires it): SendRegistrationToAppServer(token); // Subscribe to receive notifications: SubscribeToTopics(token, Topics); } } catch (Exception ex) { //LogInfo.ReportErrorInfo(ex.Message, ex.StackTrace, "RegistrationIntentService-OnHandleIntent"); } }
protected override void OnHandleIntent(Intent intent) { try { //todo force reregister on new version var prefs = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context); ISharedPreferencesEditor editor = prefs.Edit(); //var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity; //var activity = Application.Context; //var activity = intent.c Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { var instanceID = InstanceID.GetInstance(this); //-Check for make new instance id var reInstance = prefs.GetBoolean("clear_instanceid", false); if (reInstance) { try { instanceID.DeleteInstanceID(); editor.Remove("clear_instanceid"); editor.Apply(); instanceID = InstanceID.GetInstance(this); } catch (Exception e) { } } //----------------------------- var token = instanceID.GetToken( "45985897448", GoogleCloudMessaging.InstanceIdScope, null);// com.jmprog.hzinnovations.wavio Sender ID Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); SendRegistrationToAppServer(token); Subscribe(token); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token: " + e.ToString()); var registrationComplete = new Intent("registrationComplete"); registrationComplete.PutExtra("gcm_success", false); LocalBroadcastManager.GetInstance(Application.Context).SendBroadcast(registrationComplete); return; } }
public static Task <string> GetToken(Context context) { return(System.Threading.Tasks.Task.Factory.StartNew <string> (() => { var instanceID = InstanceID.GetInstance(context); var token = instanceID.GetToken(MyGcmListenerService.GCM_SENDER_ID, GoogleCloudMessaging.InstanceIdScope, null); return token; })); }
protected override Task <string> ChannelUri() { return(Task.Run(() => { var token = InstanceID.GetInstance(Application.Context) .GetToken(_config.SenderId, GoogleCloudMessaging.InstanceIdScope, new Bundle()); return token; })); }
protected override void OnHandleIntent(Intent intent) { // Get the new token and send to the server var instanceID = InstanceID.GetInstance(Application.Context); var token = instanceID.GetToken(GCM_SENDER_ID, GoogleCloudMessaging.InstanceIdScope); // Fire the event for any UI subscribed to it TokenRefreshed?.Invoke(token); Console.WriteLine("OnTokenRefresh: {0}", token); }
/// <summary> /// Unregister push notifications /// </summary> public void Unregister() { System.Diagnostics.Debug.WriteLine(string.Format("{0} - Unregister - Unregistering push notifications", PushNotificationKey.DomainName)); InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context); instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope); CrossPushNotification.PushNotificationListener.OnUnregistered(DeviceType.Android); PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, string.Empty); }
protected override void OnHandleIntent(Intent intent) { try { lock (locker) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken( GOOGLE_PROJECT_ID, GoogleCloudMessaging.InstanceIdScope, null); SendRegistrationToAppServerAndPersist(token); } } catch (Exception e) { Log.Info("RegistrationIntentService", "Failed to get a registration token "); return; } }
protected override void OnHandleIntent(Intent intent) { try { lock (locker) { var instanceId = InstanceID.GetInstance(this); var token = instanceId.GetToken("792341316392", GoogleCloudMessaging.InstanceIdScope, null); //Send token to service (azure, amazon) Subscribe(token); } } catch (Exception e) { } }
/// <summary> /// Unregister push notifications /// </summary> public void Unregister() { ThreadPool.QueueUserWorkItem(state => { System.Diagnostics.Debug.WriteLine(string.Format("{0} - Unregister - Unregistering push notifications", PushNotificationKey.DomainName)); try { InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context); instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope); CrossPushNotification.PushNotificationListener.OnUnregistered(DeviceType.Android); PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, string.Empty); }catch (IOException ex) { System.Diagnostics.Debug.WriteLine(string.Format("{0} - Error :" + ex.Message, Tag)); CrossPushNotification.PushNotificationListener.OnError(string.Format("{0} - Unregister - " + ex.ToString(), Tag), DeviceType.Android); } }); }
protected override void OnHandleIntent(Intent intent) { // Get the new token and send to the server var instanceID = InstanceID.GetInstance(Application.Context); var token = instanceID.GetToken(GCM_SENDER_ID, GoogleCloudMessaging.InstanceIdScope); // Register our GCM token with Azure notification hub servers if (hub != null) { var registration = hub.Register(token, "TEST"); Android.Util.Log.Debug(TAG, "Azure Registered: {0} -> {1}", registration.PNSHandle, registration.NotificationHubPath); } // Fire the event for any UI subscribed to it TokenRefreshed?.Invoke(token); Android.Util.Log.Debug(TAG, "GCM OnTokenRefresh: {0}", token); }
private void OnCheckedChanged(object sender, CompoundButton.CheckedChangeEventArgs e) { InstanceID id = InstanceID.GetInstance(Context); if (e.IsChecked) { Intent intent = new Intent(Activity, typeof(RegistrationIntentService)); Context.StartService(intent); } else { try { id.DeleteInstanceID(); }catch (Exception exp) { Console.Write(exp.Message); } } }
protected override void OnHandleIntent(Intent intent) { try { lock (locker) { var instanceID = InstanceID.GetInstance(this); instanceID.DeleteInstanceID(); instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken(SENDER_ID, GoogleCloudMessaging.InstanceIdScope, null); this.SendRegistrationToAppServer(token); } } catch (Exception ex) { Log.Debug(nameof(RegistrationIntentService), $"Failed to get a registration token:{ex.Message}"); } }
protected override void OnHandleIntent(Intent intent) { try { var sharedPreferences = PreferenceManager.GetDefaultSharedPreferences(this); Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { InstanceID instanceID = InstanceID.GetInstance(this); try { instanceID.DeleteInstanceID(); } catch (Java.IO.IOException e) { e.PrintStackTrace(); } instanceID = InstanceID.GetInstance(this); var sender_id = "510976446814"; var token = InstanceID.GetInstance(this).GetToken(sender_id , GoogleCloudMessaging.InstanceIdScope, null); var sentToken = sharedPreferences.GetString("token", ""); if (token != sentToken) { Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); sharedPreferences.Edit().PutString("token", token).Apply(); if (token != null && token != "") { SendRegistrationToAppServer(token); } } } } catch (Exception ex) { Log.Debug("RegistrationIntentService", "Failed to get a registration token " + ex.Message + ""); return; } }
protected override void OnHandleIntent(Intent intent) { try { Bundle extras = intent.Extras; lock (syncLock) { InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context); #if _DEBUG_ try { instanceID.DeleteInstanceID(); } catch (Exception e) { Android.Util.Log.Debug(Tag, e.ToString()); } instanceID = InstanceID.GetInstance(Android.App.Application.Context); #endif string token = instanceID.GetToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope, null); CrossPushNotification.PushNotificationListener.OnRegistered(token, DeviceType.Android); PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, token); this.SubscribeTopics(token); System.Diagnostics.Debug.WriteLine($"{token} - Device registered, registration ID={Tag}"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"{ex.Message} - Error : {Tag}"); CrossPushNotification.PushNotificationListener.OnError($"{ex.ToString()} - Register - {Tag}", DeviceType.Android); } // Intent registrationComplete = new Intent(PushNotificationKey.RegistrationComplete); // LocalBroadcastManager.GetInstance(Android.App.Application.Context).SendBroadcast(registrationComplete); }
protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (this) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken( "592518889540", GoogleCloudMessaging.InstanceIdScope, null); Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); SendRegistrationToAppServer(token); SubscribeToTopics(token, Topics); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token"); return; } }
protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { var instanceID = InstanceID.GetInstance(this); string token = instanceID.GetToken("174677789761", GoogleCloudMessaging.InstanceIdScope, null); //sender id Log.Info("RegistrationIntentService", "GCM Registration Token: " + token); SendRegistrationToAppServer(token); Subscribe(token); } } catch (Exception e) { Log.Debug("RegistrationIntentService", "Failed to get a registration token"); return; } }
protected override void OnHandleIntent(Intent intent) { try { Log.Info("RegistrationIntentService", "Calling InstanceID.GetToken"); lock (locker) { //This is the project ID - get from https://console.developers.google.com/apis/library?project=recoveriesconnect var sender_id = "935907664932"; var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken(sender_id, GoogleCloudMessaging.InstanceIdScope, null); SendRegistrationToAppServer(token); Subscribe(token); } } catch (Exception e) { return; } }
protected override void OnHandleIntent(Intent intent) { try { Log.Info(nameof(RegistrationIntentService), "Calling InstanceID.GetToken"); lock (locker) { var instanceID = InstanceID.GetInstance(this); var token = instanceID.GetToken( "912851590439", GoogleCloudMessaging.InstanceIdScope, null); Log.Info(nameof(RegistrationIntentService), "GCM Registration Token: " + token); SendRegistrationToAppServer(token); Subscribe(token); } } catch (Exception e) { Log.Debug(nameof(RegistrationIntentService), "Failed to get a registration token"); return; } }