mani gupta
mani gupta

Reputation: 109

How to bring UWP app from background (minimized mode) to foreground programmatically?

I have tried lots of options to bring the UWP app from minimized mode to foreground (Top of all running app) programmatically but not succeeded at all :(, here are the options I have tried to do the same as follow:-

1: code:- await Windows.System.Launcher.LaunchUriAsync(new Uri("yourprotocolhere://"));`

it launches but not able to bring the in the foreground but it makes the app blinking in the taskbar.

2 code: - protected override void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol) { ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;

                // Get the root frame
                Frame rootFrame = Window.Current.Content as Frame;

                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (rootFrame == null)
                {
                    // Create a Frame to act as the navigation context and navigate to the first page
                    rootFrame = new Frame();

                    rootFrame.NavigationFailed += OnNavigationFailed;

                    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                    {
                        //TODO: Load state from previously suspended application
                    }
                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;
                }
                rootFrame.Navigate(typeof(AppRootContainer));
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }

Resulted same as above one.

3: I have even tried to desktop extension with restricted capability "runFullTrust" to launch/bring the app in the foreground but still not succeeded..

Can anyone guide me to achieve the same or want to know is it possible to in UWP (bring the app in front of the screen, if app was minimized or hidden behind other apps automatically) ?

Any help would really appreciated.

Thanks in advance.

Upvotes: 2

Views: 1437

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

I have even tried to desktop extension with restricted capability "runFullTrust" to launch/bring the app in the foreground but still not succeeded

Above thread is correct, we could get current app's entries then call LaunchAsync method to launch UWP app within desktop extension.

IEnumerable<AppListEntry> appListEntries = await Package.Current.GetAppListEntriesAsync();
await appListEntries.First().LaunchAsync();

For more detail please research stefan's blog Global hotkey registration in UWP.

Upvotes: 1

Related Questions