I have a Windows Universal UWP app that I want to launch as a replacement shell on Windows 10 Home.
Typically for Win32 apps this is to set HKCU\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell to the appropriate EXE.
I have configured the UWP app with an execution alias in the Package.appxmanifest
<Extensions>
<uap5:Extension
Category="windows.appExecutionAlias"
Executable="App1.exe"
EntryPoint="App1.App">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="App1.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
I have also overridden App.OnActivated() to launch the application with this:
protected override void OnActivated(IActivatedEventArgs args)
{
switch (args.Kind)
{
case ActivationKind.CommandLineLaunch:
{
CommandLineActivatedEventArgs cmdLineArgs =
args as CommandLineActivatedEventArgs;
CommandLineActivationOperation operation = cmdLineArgs.Operation;
string cmdLineString = operation.Arguments;
string activationPath = operation.CurrentDirectoryPath;
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
rootFrame.Navigate(typeof(MainPage),
string.Format("CurrentDirectory={0}, Arguments={1}", activationPath, cmdLineString));
Window.Current.Activate();
}
}
break;
default:
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
rootFrame.Navigate(typeof(MainPage),
string.Format("CurrentDirectory={0}, Arguments={1}", Environment.CurrentDirectory, string.Empty));
Window.Current.Activate();
}
}
break;
}
}
Running App1.exe from command line works properly.
However placing the App1.exe registry: Shell='App1.exe'
does not launch the app (screen stays black on login.
I assume this is possible, because if I set Shell='Skype.exe'
Which is the execution alias for the Skype UWP app, skype launches properly on login.
I am searching for the missing piece of the puzzle.
** EDIT 2/14/21 **
So, I think the issue is that UWP apps are hosted in the explorer.exe application and if that is not running it, the app will never be able to run. Either that or it primes the UWP framework somehow.
I think Skype is likely a Hosted UWP app: Created Hosted apps
So what I have done is make a standard Win32 application that launches explorer.exe and quickly cripples it before it can display anything by implementing a keyboard hook to prevent Windows Key and other potential shortcuts, and also hiding the taskbar. Then starting the UWP app.
Its a little bit hackish, so I have not posted it as the solution, hoping that a cleaner one still is posted
Related
I have Windows 10 Pro, build 10586.494 on HP ZBook G2. When I go to Settings -> Devices -> Bluetooth and switch on Bluetooth, I can see nearby BLE devices (they are custom made BLE devices manufactured by my company).
I want to interact with my BLE devices in Universal Windows application (in Visual Studio 2015). I use this code (it is just a snippet of code)
BluetoothLEAdvertisementWatcher watcher;
//....
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
//....
private void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
}
When I run this application, WatcherOnReceived is never executed (although watcher.Start was executed). Why and how to fix it?
If found a better workaround for this. (I'm using Win 10 1803.)
First, to recap the problem since the original question is not entirely clear about it:
BluetoothLEAdvertisementWatcher works if BLE device is advertising before watcher.Start()
BluetoothLEAdvertisementWatcher does not work if BLE device starts advertising after watcher.Start()
If BluetoothLEAdvertisementWatcher is not working after watcher.Start(), it will begin working when Windows 10 Bluetooth Settings is opened or closed (i.e. the opening or closing of the settings window triggers BluetoothLEAdvertisementWatcher to start working)
So, the workaround I came up with is to keep starting and stopping a second BluetoothLEAdvertisementWatcher in the background to create the same sort of trigger that the Windows Bluetooth Settings window provides.
For example, using a WinForms timer:
...
var timer = new Timer { Interval = 1000 };
timer.Tick += Timer_Tick;
timer.Start();
...
private void Timer_Tick(object sender, EventArgs e)
{
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.Received += (s, a) => { };
watcher.Start();
Task.Delay(500).ContinueWith(_ => watcher.Stop());
}
I have to keep Bluetooth switched on in Settings -> Devices -> Bluetooth in order to receive advertisements in my app.
I implemented an IBackgroundTask on Universal Windows 10 and it works like a charm but the problem is that i want to start the app that is associated to that background task if some action occurs. The code is simple:
public sealed class AdvertisementWatcherTask : IBackgroundTask
{
private IBackgroundTaskInstance backgroundTaskInstance;
public void Run(IBackgroundTaskInstance taskInstance)
{
backgroundTaskInstance = taskInstance;
var details = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;
if (details != null)
{
//Do things
}
}
}
I've seen that you can create a ToastNotification like that:
Windows.Data.Xml.Dom.XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
Windows.Data.Xml.Dom.XmlNodeList elements = toastXml.GetElementsByTagName("text");
foreach (IXmlNode node in elements)
{
node.InnerText = taskInstance.Task.Name+ " remember to uninstall task if not debugging";
}
ToastNotification notification = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(notification);
The notification toast works good. It creates and prompts a notification and if you click it, the app that created this background task starts. This is the behaviour that I want but I want to start the app without having to click any notification. Is there any way to achieve this? Thank you.
TL;DR: I want to start the app that created the background task at some point of the code.
You can not programmatically launch URI or open app from background task. You can however display a reminder or toast notification to let user open your app.
Am finding hard to launch Cordova Windows App, from another native Windows App.
Using Protocol invocation, I am passing few parameters to Cordova Windows App, to see if the Cordova app identifies those parameters from the Windows Native App.
Is there anyway to pass Parameters from native Windows App to Cordova App, so that Cordova App identifies the parameters as arguments?
In native windows 8 store app I am using app protocol association to send parameters one app to another app. like
in sender app:
mainpage.xaml.cs on button click
var url = "apptest:?" + name;
Uri uri = new Uri(url);
await Launcher.LaunchUriAsync(uri);
in received app
Package.appxmanifest:
Declarations --> available declarations add --> protocol --> name = apptest
app.xaml.cs
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;
var rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage), protocolArgs);
Window.Current.Content = rootFrame;
}
Window.Current.Activate();
}
mainpage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ProtocolActivatedEventArgs pa = e.Parameter as ProtocolActivatedEventArgs;
if(pa != null)enter code here
{
string qS = pa.Uri.Query;
if (!string.IsNullOrEmpty(qS))
{
Txt_name.Text = qS;
}
}
}
in this way i will take the data from sender app.
Same like is there any way to receive data from windows 10 native app to cordova app. it is very hard to find the solution. not able to find the exact piece of code.
I've started using the Xamarin UITest to verify the behaviour of my application. I wanted to make the tests logically separated (by that I mean, if one test fails the other one should not fail because of the first, they should be independent). My application has multiple activities and I could not find in the documentation how to open a specific Activity.
The closest I could find was:
[SetUp]
public void BeforeEachTest()
{
app = ConfigureApp.Android.LaunchableActivity("MyActivity").StartApp ();
}
But nothing happend. Can I do this? Is there a workaround?
Thanks
A very late response but thought i'd put it up for others to find. In order to launch the app using a specific activity UITest requires two pieces of information, the app name (or APK file path) and the activity name.
Calling StartApp() on the AndroidConfigurator will look as follows for an app that is already installed onto the device or emulator:
app = ConfigureApp
.Android
.InstalledApp("packagename")
.LaunchableActivity("activityname")
.StartApp();
Or as follow for an APK file:
app = ConfigureApp
.Android
.ApkFile("filename")
.LaunchableActivity("activityname")
.StartApp();
try this code:
if (platform == Platform.Android)
{
string currentFile = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
FileInfo fi = new FileInfo(currentFile);
string dir = fi.Directory.Parent.Parent.Parent.FullName;
var PathToAPK = Path.Combine(dir, "LetsGetNative.Droid", "bin", "Debug", "LetsGetNative.Droid.apk");
app = ConfigureApp.Android.ApkFile(PathToAPK).WaitTimes(new WaitTimes()).EnableLocalScreenshots().StartApp();
}
else
{
app = ConfigureApp.iOS.StartApp();
}
How to I get access NavigationService in a Windows Phone app without going through a PhoneApplicationPage? My goal is to pass it to the application's primary view-model on startup, a technique that worked quite well for me in WPF and Silverlight.
You can get it from the app's PhoneApplicationFrame. It will be accessible from anywhere in the app since every Windows Phone app has a Frame.
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(...);
Another place to get it is from the RootFrame field in the default implementation of Application:
#region Phone application initialization
// Avoid double-initialization
private bool phoneApplicationInitialized = false;
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
#endregion