Exemplo n.º 1
0
        public static Task OpenAsync(Uri uri, BrowserLaunchType launchType)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri), "Uri cannot be null.");
            }

            var nativeUri = AndroidUri.Parse(uri.OriginalString);

            switch (launchType)
            {
            case BrowserLaunchType.SystemPreferred:
                var tabsBuilder = new Android.Support.CustomTabs.CustomTabsIntent.Builder();
                var tabsIntent  = tabsBuilder.Build();
                tabsBuilder.SetShowTitle(true);
                tabsIntent.LaunchUrl(Platform.CurrentContext, nativeUri);
                break;

            case BrowserLaunchType.External:
                var intent = new Android.Content.Intent(Android.Content.Intent.ActionView, nativeUri);
                intent.SetFlags(Android.Content.ActivityFlags.ClearTop);
                intent.SetFlags(Android.Content.ActivityFlags.NewTask);

                if (!Platform.IsIntentSupported(intent))
                {
                    throw new FeatureNotSupportedException();
                }

                Platform.CurrentContext.StartActivity(intent);
                break;
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public string OpenDirectory(string directoryPath)
        {
            DebugHandler.TraceMessage("OpenDirectory Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Directory Path: " + directoryPath, DebugSource.TASK, DebugType.PARAMETERS);

            try
            {
#if __ANDROID__
                Android.Net.Uri        uri    = Android.Net.Uri.Parse(directoryPath);
                Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionView);
                intent.SetDataAndType(uri, "*/*");
                intent.SetFlags(Android.Content.ActivityFlags.ClearWhenTaskReset | Android.Content.ActivityFlags.NewTask);
                Android.App.Application.Context.StartActivity(Android.Content.Intent.CreateChooser(intent, "Choose File Explorer"));
#else
                if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.Linux)
                {
                    Process.Start("xdg-open", directoryPath);
                }
                else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX)
                {
                    Process.Start("open", directoryPath);
                }
                else
                {
                    Process.Start("explorer.exe", directoryPath);
                }
#endif
                JsonSuccess report = new JsonSuccess()
                {
                    message = "Succesfully opened folder with path: " + directoryPath
                };

                return(report.ToJson());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Could not open directory: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError jsonError = new JsonError
                {
                    type         = "open_directory_failed",
                    errormessage = "Could not open directory.",
                    errortype    = "exception"
                };

                return(jsonError.ToJson());
            }
        }
Exemplo n.º 3
0
        public void Share_Simple_Text_File_Test()
        {
            // Save a local cache data directory file
            var file = CreateFile(FileSystem.AppDataDirectory, "share-test.txt");

            // Make sure it is where we expect it to be
            Assert.False(FileProvider.IsFileInPublicLocation(file));

            // Actually get a safe shareable file uri
            var shareableUri = FileSystemUtils.GetShareableFileUri(new ReadOnlyFile(file));

            // Launch an intent to let tye user pick where to open this content
            var intent = new Android.Content.Intent(Android.Content.Intent.ActionSend);

            intent.SetType("text/plain");
            intent.PutExtra(Android.Content.Intent.ExtraStream, shareableUri);
            intent.PutExtra(Android.Content.Intent.ExtraTitle, "Title Here");
            intent.SetFlags(Android.Content.ActivityFlags.GrantReadUriPermission);

            var intentChooser = Android.Content.Intent.CreateChooser(intent, "Pick something");

            Platform.CurrentActivity.StartActivity(intentChooser);
        }