示例#1
0
        private async Task <JsonObject> LaunchAppForResults(JsonObject json)
        {
            var appUri  = new Uri("app2scanner:"); // The protocol handled by the launched app
            var options = new LauncherOptions
            {
                TargetApplicationPackageFamilyName = "anyline.uwp.testapp_h89hmanpz8x02",
                DesiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.UseMore
            };

            var inputData = new ValueSet
            {
                ["jsonConfig"] = json.ToString()
            };

            string          scanResult = null;
            LaunchUriResult result     = await Windows.System.Launcher.LaunchUriForResultsAsync(appUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null)
            {
                ValueSet res = result.Result;
                if (result.Result.ContainsKey("result"))
                {
                    scanResult = res["result"] as string;
                }
            }
            if (scanResult != null)
            {
                var scanResultString = scanResult.ToString();
                Debug.WriteLine($"Result received: {scanResultString}");
                return(JsonObject.Parse(scanResult));
            }

            return(null);
        }
示例#2
0
        private async void Buy(string productName, string price, string filename)
        {
            var woodgroveUri = new Uri("woodgrove-pay:");

            var options = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "111055f1-4e28-4634-b304-e76934e91e53_876gvmnfevegr";

            var inputData = new ValueSet();

            inputData["ProductName"] = productName;
            inputData["Amount"]      = price;


            StorageFolder assetsFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets\\ProductImages");

            StorageFile imgFile = await assetsFolder.GetFileAsync(filename);

            inputData["ImageFileToken"] = SharedStorageAccessManager.AddFile(imgFile);


            LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(woodgroveUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result["Status"] != null &&
                (result.Result["Status"] as string) == "Success")
            {
                this.Frame.Navigate(typeof(OrderPlacedPage), result.Result);
            }
        }
        private async void OnLaunchUriForResultsUnsupportedProtocol(object sender, RoutedEventArgs e)
        {
            try
            {
                string          targetUri         = @"for-noresults:";
                string          launcherTargetPfn = @"LaunchUriTargetMultiApp_8wekyb3d8bbwe";
                Uri             uri     = new Uri(targetUri, UriKind.Absolute);
                LauncherOptions options = new LauncherOptions();
                options.TargetApplicationPackageFamilyName = launcherTargetPfn;
                LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(uri, options);

                if (result.Status == LaunchUriStatus.ProtocolUnavailable)
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_URI_BAD_PROTOCOL_SUCCESS, result.Status));
                }
                else
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_URI_BAD_PROTOCOL_SUCCESS, result.Status));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LaunchersPage.OnLaunchUriForResultsUnsupportedProtocol: " + ex.ToString());
                status.Log(ex.Message);
            }
        }
        private async Task <string> LaunchAppForResults()
        {
            var testAppUri = new Uri("demo-sampleapp:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            // Remark: This has to be the family name of the launched app!
            options.TargetApplicationPackageFamilyName = "100a09f7-0848-4e0b-8f5e-b52b18d32783_15q9a6cr6qx7p";

            var inputData = new ValueSet();

            inputData["TestData"] = this.SendDataTextBlock.Text + " at " + DateTime.Now.ToString();

            string          theResult = "";
            LaunchUriResult result    = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null &&
                result.Result.ContainsKey("ReturnedData"))
            {
                ValueSet theValues = result.Result;
                theResult = theValues["ReturnedData"] as string;
            }
            else
            {
                theResult = result.Status.ToString();
            }

            return(theResult);
        }
        private async void OnLaunchUriForResults(object sender, RoutedEventArgs e)
        {
            try
            {
                string          targetUri         = @"for-results:";
                string          launcherTargetPfn = @"LaunchUriTargetMultiApp_8wekyb3d8bbwe";
                Uri             uri     = new Uri(targetUri, UriKind.Absolute);
                LauncherOptions options = new LauncherOptions();
                options.TargetApplicationPackageFamilyName = launcherTargetPfn;
                LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(uri, options);

                if (result.Status == LaunchUriStatus.Success)
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_APP_LAUNCH_SUCCESS, targetUri));

                    // Change to validation later
                    string dataReceived = result.Result["Result"].ToString() + " : " +
                                          result.Result["UriScheme"].ToString() + " : " +
                                          result.Result["CallerPfn"].ToString();
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_FOR_RESULTS_SUCCESS, dataReceived));
                }
                else
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_FOR_RESULTS_FAIL, result.Status));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LaunchersPage.OnLaunchUriForResults: " + ex.ToString());
                status.Log(ex.Message);
            }
        }
        // 打开自定义协议 webabcd: 并传递数据给目标程序,然后获取目标程序的返回数据
        private async void btnOpenProtocol_Click(object sender, RoutedEventArgs e)
        {
            Uri uri     = new Uri("webabcd:data");
            var options = new LauncherOptions();

            // 用 LaunchUriForResultsAsync() 的话必须要指定目标程序的 PackageFamilyName
            options.TargetApplicationPackageFamilyName = "48c7dd54-1ef2-4db7-a75e-7e02c5eefd40_vsy44gny1fmrj";

            ValueSet inputData = new ValueSet();

            inputData["InputData"] = "input data";

            lblMsg.Text  = "打开 webabcd: 协议,并传递数据";
            lblMsg.Text += Environment.NewLine;

            LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(uri, options, inputData);

            if (result.Status == LaunchUriStatus.Success && result.Result != null && result.Result.ContainsKey("ReturnData"))
            {
                ValueSet theValues  = result.Result;
                string   returnData = theValues["ReturnData"] as string;

                lblMsg.Text += $"收到返回数据:{returnData}";
                lblMsg.Text += Environment.NewLine;
            }
        }
        private async void OnLaunchUriForResultsInvalidPfn(object sender, RoutedEventArgs e)
        {
            try
            {
                string          targetUri         = @"for-results:";
                string          launcherTargetPfn = @"Microsoft.Windows.Illusion_8wekyb3d8bbwe";
                Uri             uri     = new Uri(targetUri, UriKind.Absolute);
                LauncherOptions options = new LauncherOptions();
                options.TargetApplicationPackageFamilyName = launcherTargetPfn;
                LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(uri, options);

                if (result.Status == LaunchUriStatus.AppUnavailable)
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_URI_BAD_PFN_SUCCESS, result.Status));
                }
                else
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_URI_BAD_PFN_FAIL, result.Status));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LaunchersPage.OnLaunchUriForResultsInvalidPFN: " + ex.ToString());
                status.Log(ex.Message);
            }
        }
示例#8
0
        private async void BtnLaunchResult_Click(object sender, RoutedEventArgs e)
        {
            var testAppUri = new Uri("sun-targetapp:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "8dd39492-3e3d-45cc-b67f-0f00fd3bbc99_75cr2b68sm664";
            List <Goods> goodselectlist = new List <Goods> {
            };

            for (int i = 0; i < goodslist.Count; i++)
            {
                if (goodslist[i].IsSelected)
                {
                    goodselectlist.Add(goodslist[i]);
                }
            }
            string items     = JSONHelper.JsonSerializer(goodselectlist);
            var    inputData = new ValueSet();

            inputData["Items"] = items;

            LaunchUriResult result = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null &&
                result.Result.ContainsKey("ReturnData"))
            {
                ValueSet theValues = result.Result;
                TxtAmount.Text = string.Format("Total{0},already paid successful", theValues["ReturnData"] as string);
                return;
            }
        }
        private async void Crop_Click(object sender, RoutedEventArgs e)
        {
            #region File Setup
            // Load a File Picker that shows image file types
            FileOpenPicker open = new FileOpenPicker();
            open.FileTypeFilter.Add(".jpg");
            open.FileTypeFilter.Add(".png");
            open.FileTypeFilter.Add(".jpeg");
            open.ViewMode = PickerViewMode.Thumbnail;
            open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            open.CommitButtonText       = "Open";

            // Wait for user to select a file
            StorageFile source = await open.PickSingleFileAsync();

            // Verify the source is not null
            if (source != null)
            {
                try
                {
                    // Create a destination file
                    StorageFile dest = await KnownFolders.PicturesLibrary.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);

                    #endregion

                    // Call CropImageAsync and receive Result
                    LaunchUriResult result = await this.CropImageAsync(source, dest, 500, 500);

                    // Load Destination Image into Image Preview
                    var stream = await dest.OpenReadAsync();

                    await AppData.currentImage.SetSourceAsync(stream);

                    #region Error Handling
                    // Verify result and load picture into the source
                    if (result.Status == LaunchUriStatus.Success && result.Result != null)
                    {
                        string imgstr = await ImageTools.FileToString(dest);

                        if (imgstr != null)
                        {
                            await AppData.currentImage.SetSourceAsync(ImageTools.DecodeStringToBitmapSource(imgstr));

                            AppData.currentImageString = imgstr;
                        }
                    }
                }
                catch
                {
                    MessageDialog md = new MessageDialog("Error loading image file.");
                    await md.ShowAsync();
                }
            }
            #endregion
        }
示例#10
0
        private async void BtnLaunchc_Click(object sender, RoutedEventArgs e)
        {
            var testAppUri = new Uri("sun-targetapp:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "3f162b5e-98e5-4118-a2d9-8882398d7d8d_75cr2b68sm664";

            var inputData = new ValueSet();

            inputData["Items"] = "aaa";
            LaunchUriResult result = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);
        }
        async Task <ValueSet> LaunchAppForResults(string source)
        {
            var testAppUri = new Uri($"barcodemgr:reader?source={source}");
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = ((RadioButton)(TargetAppRadioButtons.SelectedItem)).Tag.ToString();

            ValueSet        keyValuePairs = null;
            LaunchUriResult result        = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null)
            {
                keyValuePairs = result.Result;
            }
            return(keyValuePairs);
        }
示例#12
0
        private async void OnOpenAnotherAppWithResultsClicked(object sender, RoutedEventArgs e)
        {
            ValueSet data = new ValueSet();

            data.Add("num1", 10);

            LauncherOptions options = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "467a521c-d93f-4c82-bfab-d18f4a8482f0_e8f4dqfvn1be6";

            LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(new Uri("sum:"), options, data);

            if (result.Status == LaunchUriStatus.Success)
            {
                ValueSet      resultData = result.Result;
                int           sum        = (int)resultData["sum"];
                MessageDialog dialog     = new MessageDialog($"The sum is {sum}");
                await dialog.ShowAsync();
            }
        }
示例#13
0
        private async void ButtonSelect_Click(object sender, RoutedEventArgs e) {
            try {
                // Create a destination file
                StorageFile dest = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);

                // Call CropImageAsync and receive Result
                LaunchUriResult result = await this.CropImageAsync(dest, 500, 500);

                // Load Destination Image into Image Preview
                var stream = await dest.OpenReadAsync();

                var bm = new BitmapImage();
                await bm.SetSourceAsync(stream);

                this.croppedImage.Source = bm;

            } catch {
                MessageDialog md = new MessageDialog("Error loading image file.");
                await md.ShowAsync();
            }
        }
        private async void OnLaunchUriForResultsWithData(object sender, RoutedEventArgs e)
        {
            try
            {
                string          targetUri         = @"for-results:";
                string          targetUriScheme   = @"for-results";
                string          launcherTargetPfn = @"LaunchUriTargetMultiApp_8wekyb3d8bbwe";
                Uri             uri     = new Uri(targetUri, UriKind.Absolute);
                LauncherOptions options = new LauncherOptions();
                options.TargetApplicationPackageFamilyName = launcherTargetPfn;
                ValueSet data       = new ValueSet();
                long     timeSuffix = DateTime.Now.ToFileTimeUtc();
                timeSuffix = (timeSuffix / 10000000000L);
                data.Add("Data", "Hello Target App_" + timeSuffix);
                data.Add("UriScheme", targetUriScheme);
                LaunchUriResult result = await Launcher.LaunchUriForResultsAsync(uri, options, data);

                if (result.Status == LaunchUriStatus.Success)
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_APP_LAUNCH_SUCCESS, targetUri));
                    string dataReceived = result.Result["Result"].ToString() + " : " +
                                          result.Result["UriScheme"].ToString() + " : " +
                                          result.Result["CallerPfn"].ToString() + " : " +
                                          result.Result["DataStatus"].ToString();
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_FOR_RESULTS_WITH_DATA_SUCCESS, dataReceived));
                }
                else
                {
                    status.Log(string.Format(CultureInfo.CurrentCulture,
                                             LocalizableStrings.LAUNCHERS_APP_LAUNCH_FAIL, result.Status));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LaunchersPage.OnLaunchUriForResultsWithData: " + ex.ToString());
                status.Log(ex.Message);
            }
        }
示例#15
0
        private async void ButtonOpen_Click(object sender, RoutedEventArgs e) {

            // Load a File Picker that shows image file types
            FileOpenPicker open = new FileOpenPicker();
            open.FileTypeFilter.Add(".jpg");
            open.FileTypeFilter.Add(".png");
            open.FileTypeFilter.Add(".jpeg");
            open.ViewMode = PickerViewMode.Thumbnail;
            open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            open.CommitButtonText = "Open";

            // Wait for user to select a file 
            StorageFile source = await open.PickSingleFileAsync();

            // Verify the source is not null
            if (source != null) {
                try {
                    // Create a destination file
                    StorageFile dest = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("Cropped.jpg", CreationCollisionOption.ReplaceExisting);

                    // Call CropImageAsync and receive Result
                    LaunchUriResult result = await this.CropImageAsync(source, dest, 500, 500);

                    // Load Destination Image into Image Preview
                    var stream = await dest.OpenReadAsync();

                    var bm = new BitmapImage();
                    await bm.SetSourceAsync(stream);

                    this.croppedImage.Source = bm;

                } catch {
                    MessageDialog md = new MessageDialog("Error loading image file.");
                    await md.ShowAsync();
                }

            }
        }
示例#16
0
        public async Task <string> LaunchAppForResults()
        {
            var testAppUri = new Uri("test-app2app:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "b28ed3ce-a523-49f4-a46f-ef5b8f91ad1d_a1691p6wrfp9c";

            var inputData = new ValueSet();

            inputData["TestData"] = "Test data";

            string          theResult = "";
            LaunchUriResult result    = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null &&
                result.Result.ContainsKey("ReturnedData"))
            {
                ValueSet theValues = result.Result;
                theResult = theValues["ReturnedData"] as string;
            }
            return(theResult);
        }
示例#17
0
        async Task <string> LaunchAppForResults()
        {
            var testAppUri = new Uri("test-app2app:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "67d987e1-e842-4229-9f7c-98cf13b5da45_yd7nk54bq29ra";

            var inputData = new ValueSet();

            inputData["TestData"] = "Test data";

            string          theResult = "";
            LaunchUriResult result    = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);

            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null &&
                result.Result.ContainsKey("ReturnedData"))
            {
                ValueSet theValues = result.Result;
                theResult = theValues["ReturnedData"] as string;
            }
            return(theResult);
        }
示例#18
0
        private async void BtnLaunchResult_Click(object sender, RoutedEventArgs e)
        {
            var testAppUri = new Uri("sun-targetapp:"); // The protocol handled by the launched app
            var options    = new LauncherOptions();

            options.TargetApplicationPackageFamilyName = "8dd39492-3e3d-45cc-b67f-0f00fd3bbc99_75cr2b68sm664";
            List <Goods> goodselectlist = new List <Goods> {
            };

            for (int i = 0; i < goodslist.Count; i++)
            {
                if (goodslist[i].IsSelected)
                {
                    goodselectlist.Add(goodslist[i]);
                }
            }
            string items     = JSONHelper.JsonSerializer(goodselectlist);
            var    inputData = new ValueSet();

            inputData["Items"] = items;

            #region  valueset exceed
            //string content;
            //var Folder1 = Windows.Storage.ApplicationData.Current.LocalFolder;
            //var shareFile = await Folder1.GetFileAsync("App Communication(Sunteen Checkpoint Preview).pptx");
            //using (Stream stream = await shareFile.OpenStreamForReadAsync())
            //{
            //    StreamReader reader = new StreamReader(stream);
            //    content = reader.ReadToEnd();
            //    System.Text.Encoding.UTF8.GetBytes(content);
            //}
            //inputData.Add("test", content);
            #endregion

            LaunchUriResult result = await Windows.System.Launcher.LaunchUriForResultsAsync(testAppUri, options, inputData);

            #region
            if (result.Status == LaunchUriStatus.Success &&
                result.Result != null &&
                result.Result.ContainsKey("ReturnData"))
            {
                ValueSet theValues = result.Result;
                TxtAmount.Text = string.Format("Total{0},already paid successful", theValues["ReturnData"] as string);
                return;
            }
            switch (result.Status)
            {
            case LaunchUriStatus.AppUnavailable:
                rootPage.NotifyUser("The application cannot be activated which may be because it is being updated by the store, it was installed on a removable device that is not available, and so on", NotifyType.ErrorMessage);
                break;

            case LaunchUriStatus.ProtocolUnavailable:
                rootPage.NotifyUser("The application you are trying to activate does not support this URI", NotifyType.ErrorMessage);
                break;

            case LaunchUriStatus.Unknown:
            default:
                rootPage.NotifyUser("User canceled or Unknown error", NotifyType.ErrorMessage);
                break;
            }
            #endregion
        }