Exemplo n.º 1
0
        //Get network connection name
        internal static async Task <string> GetNetworkName()
        {
            try
            {
                //Check connection
                ConnectionProfile ConnectionProfile = NetworkInformation.GetInternetConnectionProfile();
                if (ConnectionProfile == null)
                {
                    return("No connection");
                }
                else
                {
                    //Get Wi-Fi / Ethernet name
                    string FirstNetwork = ConnectionProfile.GetNetworkNames().FirstOrDefault();
                    if (!string.IsNullOrWhiteSpace(FirstNetwork))
                    {
                        return(FirstNetwork);
                    }

                    //Get Cellular name
                    if (ConnectionProfile.IsWwanConnectionProfile)
                    {
                        PhoneCallStore phoneCallStore = await PhoneCallManager.RequestStoreAsync();

                        PhoneLine phoneLine = await PhoneLine.FromIdAsync(await phoneCallStore.GetDefaultLineAsync());

                        return(phoneLine.NetworkName);
                    }

                    return("Unknown");
                }
            }
            catch { return("Unknown"); }
        }
Exemplo n.º 2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (_LineWatcher == null)
            {
                PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                _LineWatcher              = store.RequestLineWatcher();
                _LineWatcher.LineAdded   += _watcher_LineAdded;
                _LineWatcher.LineRemoved += _watcher_LineRemoved;

                _LineWatcher.Start();
            }
            string str = PhoneLineTransportDevice.GetDeviceSelector(PhoneLineTransport.Bluetooth);

            if (_DeviceWatcher == null)
            {
                _DeviceWatcher          = DeviceInformation.CreateWatcher(str);
                _DeviceWatcher.Added   += _DeviceWatcher_Added;
                _DeviceWatcher.Removed += _DeviceWatcher_Removed;

                _DeviceWatcher.Start();
            }

            string str1  = BluetoothDevice.GetDeviceSelector();
            var    watch = DeviceInformation.CreateWatcher(str1);

            watch.Added   += _DeviceWatcher_Added;
            watch.Removed += _DeviceWatcher_Removed;
            watch.Start();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Enumerate through all phone lines and returns a list of all phone lines
        /// </summary>
        /// <returns>A dictionary of cellular phone lines and their guids.</returns>
        private async Task <Dictionary <Guid, PhoneLine> > GetPhoneLinesAsync()
        {
            PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

            // Start the PhoneLineWatcher
            var watcher    = store.RequestLineWatcher();
            var phoneLines = new List <PhoneLine>();
            var lineEnumerationCompletion = new TaskCompletionSource <bool>();

            watcher.LineAdded            += async(o, args) => { var line = await PhoneLine.FromIdAsync(args.LineId); phoneLines.Add(line); };
            watcher.Stopped              += (o, args) => lineEnumerationCompletion.TrySetResult(false);
            watcher.EnumerationCompleted += (o, args) => lineEnumerationCompletion.TrySetResult(true);
            watcher.Start();

            // Wait for enumeration completion
            if (!await lineEnumerationCompletion.Task)
            {
                throw new Exception("Phone Line Enumeration failed");
            }

            watcher.Stop();

            Dictionary <Guid, PhoneLine> returnedLines = new Dictionary <Guid, PhoneLine>();

            foreach (PhoneLine phoneLine in phoneLines)
            {
                if (phoneLine != null && phoneLine.Transport == PhoneLineTransport.Cellular)
                {
                    returnedLines.Add(phoneLine.Id, phoneLine);
                }
            }

            return(returnedLines);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the default phone line
        /// </summary>
        /// <returns>A one phone line. The default one on the device.</returns>
        private async Task <PhoneLine> GetDefaultPhoneLineAsync()
        {
            PhoneCallStore phoneCallStore = await PhoneCallManager.RequestStoreAsync();

            Guid lineId = await phoneCallStore.GetDefaultLineAsync();

            return(await PhoneLine.FromIdAsync(lineId));
        }
Exemplo n.º 5
0
        public static string DEBUG = "+420604540531";    /*INSERT NUMBER*/

        public static async Task CallAsync()
        {
            PhoneCallStore PhoneCallStore = await PhoneCallManager.RequestStoreAsync();

            Guid LineGuid = await PhoneCallStore.GetDefaultLineAsync();

            PhoneLine line = await PhoneLine.FromIdAsync(LineGuid);

            line.Dial(DEBUG, "CALL");
        }
Exemplo n.º 6
0
        public static async Task <bool> EnsureInitPhoneLineWatcher()
        {
            if (LineWatcher == null)
            {
                PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                if (store == null)
                {
                    return(false);
                }
                LineWatcher              = store.RequestLineWatcher();
                LineWatcher.LineAdded   += LineWatcher_LineAdded;
                LineWatcher.LineRemoved += LineWatcher_LineRemoved;
                LineWatcher.LineUpdated += LineWatcher_LineUpdated;
            }

            return(true);
        }
Exemplo n.º 7
0
        private async void listView_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            if (listView.SelectedItem != null)
            {
                contato = listView.SelectedItem as Contato;
                PhoneCallStore phoneCallStore =
                    await PhoneCallManager.RequestStoreAsync();

                Guid lineGuid = await phoneCallStore.GetDefaultLineAsync();

                MessageDialog msg = new MessageDialog(lineGuid.ToString());
                await msg.ShowAsync();

                PhoneLine phoneLine = await PhoneLine.FromIdAsync(lineGuid);

                phoneLine.Dial(contato.Fone, contato.Nome);
            }
        }
        private async void PlaceCall(string number)
        {
            try
            {
                PhoneCallStore PhoneCallStore = await PhoneCallManager.RequestStoreAsync();

                Guid LineGuid = await PhoneCallStore.GetDefaultLineAsync();

                var phoneLine = await PhoneLine.FromIdAsync(LineGuid);

                phoneLine.Dial(number, "New Call");
            }
            catch
            {
                var uri    = $"callto:{number}";
                var launch = await Launcher.LaunchUriAsync(new Uri(uri));
            }
        }
Exemplo n.º 9
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            switch ((sender as Button).Content.ToString())
            {
            case "Contact Doctor":
                PhoneCallStore PhoneCallStore = await PhoneCallManager.RequestStoreAsync();

                Guid LineGuid = await PhoneCallStore.GetDefaultLineAsync();

                var phoneCall = await PhoneLine.FromIdAsync(LineGuid);

                phoneCall.Dial(phNo.Text, name.Text);
                break;

            case "View List":
                viewList.Visibility   = Visibility.Visible;
                viewSingle.Visibility = Visibility.Collapsed;
                break;

            default:
                break;
            }
        }
Exemplo n.º 10
0
        private async void Load()
        {
            string displayname = "";

            if (device != null)
            {
                if (device.AccountPhoneNumber != null)
                {
                    displayname = device.AccountPhoneNumber;
                }

                switch (device.DeviceStatus)
                {
                case SmsDeviceStatus.DeviceBlocked:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.DeviceFailure:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.DeviceLocked:
                {
                    StatusIcon.Text = "";
                    break;
                }

                case SmsDeviceStatus.Off:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.Ready:
                {
                    StatusIcon.Text = "";
                    var pad = StatusIcon.Padding;
                    pad.Top            = 0;
                    StatusIcon.Padding = pad;
                    break;
                }

                case SmsDeviceStatus.SimNotInserted:
                case SmsDeviceStatus.SubscriptionNotActivated:
                case SmsDeviceStatus.BadSim:
                {
                    StatusIcon.Text = "";
                    break;
                }
                }
            }

            try
            {
                string selectorStr = MobileBroadbandModem.GetDeviceSelector();
                DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selectorStr);

                foreach (var mdevice in devices)
                {
                    MobileBroadbandModem modem = MobileBroadbandModem.FromId(mdevice.Id);
                    if (modem.DeviceInformation.TelephoneNumbers.Count > 0)
                    {
                        if (modem.DeviceInformation.TelephoneNumbers.Any(x => x == device.AccountPhoneNumber))
                        {
                            displayname = modem.CurrentNetwork.RegisteredProviderName;

                            // from https://github.com/ADeltaX/MobileShell/blob/experiments/src/App.xaml.cs
                            PhoneCallStore store = await PhoneCallManager.RequestStoreAsync();

                            PhoneLineWatcher            watcher    = store.RequestLineWatcher();
                            List <PhoneLine>            phoneLines = new List <PhoneLine>();
                            TaskCompletionSource <bool> lineEnumerationCompletion = new TaskCompletionSource <bool>();

                            watcher.LineAdded            += async(o, args) => { var line = await PhoneLine.FromIdAsync(args.LineId); phoneLines.Add(line); };
                            watcher.Stopped              += (o, args) => lineEnumerationCompletion.TrySetResult(false);
                            watcher.EnumerationCompleted += (o, args) => lineEnumerationCompletion.TrySetResult(true);

                            watcher.Start();

                            if (await lineEnumerationCompletion.Task)
                            {
                                watcher.Stop();

                                List <PhoneLine> returnedLines = new List <PhoneLine>();

                                foreach (PhoneLine phoneLine in phoneLines)
                                {
                                    if (phoneLine != null && phoneLine.Transport == PhoneLineTransport.Cellular)
                                    {
                                        returnedLines.Add(phoneLine);
                                    }
                                }

                                if (returnedLines.Any(x => x.NetworkName == modem.CurrentNetwork.RegisteredProviderName))
                                {
                                    var line = returnedLines.First(x => x.NetworkName == modem.CurrentNetwork.RegisteredProviderName);
                                    displayname += " (SIM " + (line.CellularDetails.SimSlotIndex + 1) + ")";
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch
            {
            }

            if (string.IsNullOrEmpty(displayname))
            {
                displayname = "Unidentified SIM";
            }

            LineName.Text = displayname;
        }