async Task Subscribe() { // Wait for a connection to GPS if (!await IsConnected()) { return; } var status = await NearbyClass.Messages.SubscribeAsync(googleApiClient, emotionsMsgListener); if (!status.IsSuccess) { await App.Current.MainPage.DisplayAlert(string.Empty, status.StatusMessage, "Okay"); } else { await App.Current.MainPage.DisplayAlert("Subscribe", status.StatusMessage, "Okay"); } if (status.IsSuccess) { NearbyClass.GetMessagesClient(this).Subscribe(emotionsMsgListener); } }
public async Task SubscribeMessagesAsync() { //Intent intent = new Intent(Android.App.Application.Context, typeof(PresenceNotificationReceiverActivity)); //intent.SetFlags(ActivityFlags.NewTask); //Android.App.Application.Context.StartActivity(intent); _messageListener = new PresenceMessageListener(); await NearbyClass.GetMessagesClient(MainActivity.CurrentMainActivity).SubscribeAsync(_messageListener); }
public async Task PublishPresenceNotificationAsync(string messageString) { //Intent intent = new Intent(Android.App.Application.Context, typeof(PresenceNotificationSenderActivity)); //intent.PutExtra("presenceId", messageString); //intent.SetFlags(ActivityFlags.NewTask); //Android.App.Application.Context.StartActivity(intent);string messageString = Intent.GetStringExtra("presenceId"); byte[] messageByte = Encoding.UTF8.GetBytes(messageString); _message = new Android.Gms.Nearby.Messages.Message(messageByte); await NearbyClass.GetMessagesClient(MainActivity.CurrentMainActivity).PublishAsync(_message); }
protected override void OnStart() { googleApiClient.Connect(); RequestNearbyPermissionsAsync(); base.OnStart(); var array = Encoding.ASCII.GetBytes(new string(' ', 100)); publishedMessage = new NearbyMessage(array, "lolade1", "lolade2"); //googleApiClient.Connect(); NearbyClass.GetMessagesClient(this).Publish(publishedMessage); NearbyClass.GetMessagesClient(this).Subscribe(emotionsMsgListener); }
async Task Publish() { try { // Wait for connection if (!await IsConnected()) { return; } //if (!IsConnectedToNetwork) //{ // await App.Current.MainPage.DisplayAlert(string.Empty, "Not connected to network", "Okay"); // return; //} // Create new Nearby message to publish with the spinner choices dynamic Message = new { message = "hello" }; // var sevenItems = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; string myMessage = "This is lolade"; var array = Encoding.ASCII.GetBytes(myMessage); // Remove any existing messages for this user from our list // Add the new message and update the dataset // If we already published a message, unpublish it first if (publishedMessage != null) { await Unpublish(); } // Create a new nearby message with our serialized object //publishedMessage = new NearbyMessage(Message?.Serialize()); publishedMessage = new NearbyMessage(array); var getMsg = NearbyClass.GetMessagesClient(this); var status = await NearbyClass.Messages.PublishAsync(googleApiClient, publishedMessage); if (!status.IsSuccess) { await App.Current.MainPage.DisplayAlert("Publish", status.StatusMessage, "Okay"); } else { await App.Current.MainPage.DisplayAlert("Publish", status.StatusMessage, "Okay"); } if (status.IsSuccess) { NearbyClass.GetMessagesClient(this).Publish(publishedMessage); } } catch (Exception ex) { await App.Current.MainPage.DisplayAlert("Publish", ex.ToString(), "Okay"); } }
public async Task UnsubscribePresenceNotificationAsync() { await NearbyClass.GetMessagesClient(MainActivity.CurrentMainActivity).UnsubscribeAsync(_messageListener); }
public async Task UnpublishPresenceNotificationAsync() { await NearbyClass.GetMessagesClient(MainActivity.CurrentMainActivity).UnpublishAsync(_message); }