async void DownloadGraphBtn_Tapped(object sender, EventArgs e)
        {
#if DEBUG
            string qrCodeValue = string.Empty;
            if (DeviceInfo.DeviceType == DeviceType.Virtual)
            {
                qrCodeValue = "https://drive.google.com/uc?authuser=0&id=1TakJcYBgZ07s4WrF1-n6p5mgqttjX5UL&export=download@OpenISDM";
            }
            else
            {
                IQrCodeDecoder qrCodeDecoder = DependencyService.Get <IQrCodeDecoder>();
                qrCodeValue = await qrCodeDecoder.ScanAsync();
            }
#else
            // 開啟鏡頭掃描Barcode
            IQrCodeDecoder qrCodeDecoder = DependencyService.Get <IQrCodeDecoder>();
            string         qrCodeValue   = await qrCodeDecoder.ScanAsync();

            // In iOS, if the User has denied the permission, you might not be able to request for permissions again.
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);

            if (status != PermissionStatus.Granted)
            {
                //await DisplayAlert("Oops...", "Sorry for that you denied the permission of camera so you can't scan the QR code.", "OK");
            }
#endif

            if (!string.IsNullOrEmpty(qrCodeValue))
            {
                // 判斷是URL還是一般字串
                if ((qrCodeValue.Substring(0, 7) == "http://") || (qrCodeValue.Substring(0, 8) == "https://"))
                {
                    // 判斷是圖資或者網頁
                    string[] buffer = qrCodeValue.Split('@');
                    if (buffer[buffer.Length - 1] == "OpenISDM")
                    {
                        // 開啟輸入圖資名稱對話頁
                        downloadURL = buffer[0];
                        await PopupNavigation.Instance.PushAsync(downloadPage as DownloadPopUpPage);
                    }
                    else
                    {
                        // 使用瀏覽器開啟網頁
                        bool answer = await DisplayAlert("通知", "是否開啟網頁", "Yes", "No");

                        if (answer)
                        {
                            await Browser.OpenAsync(qrCodeValue, BrowserLaunchMode.SystemPreferred);
                        }
                    }
                }
                else
                {
                    await DisplayAlert("QrCode內容", qrCodeValue, "OK");
                }
            }
        }
示例#2
0
        async void DownloadGraphBtn_Tapped(object sender, EventArgs e)
        {
#if DEBUG
            string qrCodeValue = string.Empty;
            if (DeviceInfo.DeviceType == DeviceType.Virtual)
            {
                // qrCodeValue = "https://drive.google.com/uc?authuser=0&id=1C-JgyOHEikxuqgVi9S7Ww9g05u2Jb3-q&export=download@OpenISDM";
                qrCodeValue = "https://drive.google.com/uc?authuser=0&id=1w_cc8pp483Dd5KTbM3-JaCelhMh8wTQs&export=download@OpenISDM";
            }
            else
            {
                IQrCodeDecoder qrCodeDecoder   = DependencyService.Get <IQrCodeDecoder>();
                var            currentLanguage = CrossMultilingual.Current.CurrentCultureInfo;
                if (Connectivity.NetworkAccess == NetworkAccess.Internet)
                {
                    qrCodeValue = await qrCodeDecoder.ScanAsync();
                }
                else
                {
                    await DisplayAlert(
                        _resourceManager.GetString("WARN_STRING", currentLanguage),
                        _resourceManager.GetString("PLEASE_CHECK_INTERNET_STRING", currentLanguage),
                        _resourceManager.GetString("CANCEL_STRING", currentLanguage));
                }
            }
#else
            // Open the camera to scan Barcode
            IQrCodeDecoder qrCodeDecoder = DependencyService.Get <IQrCodeDecoder>();
            string         qrCodeValue   = await qrCodeDecoder.ScanAsync();

            // In iOS, if the User has denied the permission, you might not be able to request for
            // permissions again.

            /*
             * var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);
             * if (status != PermissionStatus.Granted)
             * {
             * }*/
#endif

            if (!string.IsNullOrEmpty(qrCodeValue))
            {
                var currentLanguage = CrossMultilingual.Current.CurrentCultureInfo;
                // Determine it is URL or string
                if ((qrCodeValue.Substring(0, 7) == "http://") ||
                    (qrCodeValue.Substring(0, 8) == "https://"))
                {
                    // Determine it is map data or website
                    string[] buffer = qrCodeValue.Split('@');
                    if (buffer[buffer.Length - 1] == "OpenISDM")
                    {
                        // open the page to input the data
                        _downloadURL = buffer[0];

                        await PopupNavigation.Instance.PushAsync(_downloadPage as DownloadPopUpPage);
                    }
                    else
                    {
                        // Use the browser to open data
                        bool answer = await DisplayAlert(_resourceManager.GetString("NOTIFY_STRING", currentLanguage),
                                                         _resourceManager.GetString("SURE_TO_OPEN_WEBSITE_STRING", currentLanguage),
                                                         _resourceManager.GetString("OK_STRING", currentLanguage),
                                                         _resourceManager.GetString("CANCEL_STRING", currentLanguage));

                        if (answer)
                        {
                            await Browser.OpenAsync(qrCodeValue, BrowserLaunchMode.SystemPreferred);
                        }
                    }
                }
                else
                {
                    await DisplayAlert(_resourceManager.GetString("QRCODE_CONTENT_STRING", currentLanguage),
                                       qrCodeValue,
                                       _resourceManager.GetString("OK_STRING", currentLanguage));
                }
            }
        }