コード例 #1
0
        public override async void OnMessageReceived(RemoteMessage message)
        {
            base.OnMessageReceived(message);

            try
            {
                if (!message.Data.ContainsKey("Action"))
                {
                    throw new InvalidOperationException();
                }
                else if (message.Data["Action"] == "Wake")
                {
#if DEBUG
                    SendNotification("Wake", "Wake");
#endif
                    var intent = new Intent(this, typeof(MessageCarrierService));
                    intent.PutExtra("Action", "Wake");
                    StartService(intent);
                }
                else if (message.Data["Action"] == "SendCarrier")
                {
#if DEBUG
                    SendNotification("SendCarrier", "SendCarrier");
#endif
                    var intent = new Intent(this, typeof(MessageCarrierService));
                    intent.PutExtra("Action", "SendCarrier");
                    intent.PutExtra("DeviceId", message.Data["WakerDeviceId"]);

                    Android.Util.Log.Debug("CARRIER_DEBUG", "1");

                    StartService(intent);
                }
                else if (message.Data["Action"] == "Payload")
                {
#if DEBUG
                    SendNotification("Payload", "Payload");
#endif
                    var intent = new Intent(this, typeof(WaiterService));
                    intent.PutExtra("Data", message.Data["Data"]);

                    StartService(intent);
                }
                else if ((message.Data["Action"] == "LaunchUrl") && (message.Data.ContainsKey("Url")))
                {
                    try
                    {
                        string url = message.Data["Url"];
                        LaunchHelper.LaunchUrl(this, url);
                    }
                    catch (Exception ex)
                    {
                        Log.Debug(TAG, ex.Message);
                        ToastHelper.ShowToast(this, "Couldn't launch URL.", Android.Widget.ToastLength.Long);
                    }
                }
                else if ((message.Data["Action"] == "FastClipboard") && (message.Data.ContainsKey("SenderName")) && (message.Data.ContainsKey("Text")))
                {
                    string senderName = message.Data["SenderName"];
                    string text       = message.Data["Text"];

                    Guid guid = await TextReceiver.QuickTextReceivedAsync(senderName, text);

                    await ClipboardHelper.CopyTextToClipboard(this, guid);
                }
                else if (message.Data["Action"] == "CloudClipboard")
                {
                    if (message.Data.ContainsKey("Data"))
                    {
                        string text = message.Data["Data"];

                        var settings = new Settings(this);

                        if (message.Data.ContainsKey("AccountId"))
                        {
                            if (CrossSecureStorage.Current.HasKey("RoamitAccountId"))
                            {
                                CrossSecureStorage.Current.DeleteKey("RoamitAccountId");
                            }

                            CrossSecureStorage.Current.SetValue("RoamitAccountId", message.Data["AccountId"]);
                        }

                        if (settings.CloudClipboardReceiveMode == CloudClipboardReceiveMode.Automatic)
                        {
                            CloudClipboardNotifier.SetCloudClipboardValue(this, text);
                        }
                        else
                        {
                            settings.CloudClipboardText = text;
                            CloudClipboardNotifier.SendCloudClipboardNotification(this, text);
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            catch (InvalidOperationException)
            {
                SendNotification($"Action '{message.Data["Action"]}' not supported.", "Please make sure the app is updated to enjoy latest features.");
            }
        }
コード例 #2
0
 private void HistoryAdapter_UrlLaunchRequested(object sender, HistoryListItem e)
 {
     LaunchHelper.LaunchUrl(this, (e.Data.Data as ReceivedUrl).Uri.OriginalString);
 }