I have 2 windows apps in which one is native and one is cordova windows app.
user will be having some set of navigations from windows native app which would invoke the respective page in cordova app depending up on the URI invoked from native app.
i am actually new to cordova. The similar thing in native i should be able to handle using below code
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
var _args = args as ProtocolActivatedEventArgs;
argValues.Add(_args.Uri.ToString());
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
rootFrame.Navigate(typeof(MainPage), argValues);
}
Window.Current.Activate();
// TODO: Handle URI activation
// The received URI is eventArgs.Uri.AbsoluteUri
}
}
The above app lifecycle event is been added to Application class(app.xaml). But didn't saw similar application class in cordova window app. If application class can be added to Cordova I would like to develop a similar plugin like cordova-webintent https://github.com/Initsogar/cordova-webintent
I saw one corodva windows plugin but it supports only for win8 Phone
cordova-urlhandler-plugin
Related
In Windows 10, when I hit e.g. SHIFT + WIN + S I can take a screenshot of my screen.
In other cases I have my webcam that can take a picture, and so on.
All those scenarios have the feature to "Share" the captured image to another app, e.g. Mail, OneNote, etc.
I would like to register my own UWP app to be the recipient of such Share, so that the user can manipulate the captured image in my UWP app.
Is there a way to configure my UWP app to do this?
Is there a way to configure my UWP app to do this?
Yes, you could make your UWP app a receiver when you want to share some content from other apps.
Declare your app as a share target. Open the manifest file. Find the Declarations tab, then choose Share Target from the Available Declarations list, and then select Add.
Set the file types and formats based on your requirements in the Declarations. For example, if you need to receive a screenshot, you will need to add Bitmap in the Data format.
Handle share activation in the App.Xaml.cs by handling the Application.OnShareTargetActivated event.
I've made a simple test about this and you could refer to it. For more information about this, you could also check this document: Receive data
Manifest file:
App.xaml.cs:
protected override async void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
{
ShareOperation shareOperation = args.ShareOperation;
if (shareOperation.Data.Contains(StandardDataFormats.Bitmap))
{
var imageStream = await shareOperation.Data.GetBitmapAsync();
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
rootFrame.Navigate(typeof(ShareImagePage), imageStream);
Window.Current.Activate();
}
}
ShareImagePage:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Content != null)
{
IRandomAccessStreamReference imageReceived = null;
imageReceived = e.Parameter as IRandomAccessStreamReference;
using (var imageStream = await imageReceived.OpenReadAsync())
{
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
imgImage.Source = bitmapImage;
}
}
}
I'm writing a UWP app, and I have a ScheduledToastNotification that is added to the schedule when the app is suspended (e.g. like a reminder). However, if I close the app, the notification appears on time, but when I click on the notification (no buttons, just on the notification in general), the app doesn't launch correctly, stopping at the splash screen.
How do I get the app the re-launch correctly?
Thanks.
You should override OnActivated in App.Xaml.cs and handle this like
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.ToastNotification)
{
var toastArgs = args as ToastNotificationActivatedEventArgs;
var arguments = toastArgs.Argument;
if (arguments == "ARG")
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
Window.Current.Content = rootFrame;
}
rootFrame.Navigate(typeof(YOURPAGE));
Window.Current.Activate();
}
}
}
I am making a Windows 8.1 speech based application. My problem is that when I give Cortana the input it launches my app and the app closes at the splashscreen, but when I run my app in background (minimize the app) or when the app is running, the Cortana input works perfect.
Where am I going wrong? Here is my app.xaml.cs code, in the OnActivatedMethod:
if (args.Kind == ActivationKind.VoiceCommand)
{
VoiceCommandActivatedEventArgs vcArgs = (VoiceCommandActivatedEventArgs)args;
string voiceCommandName = vcArgs.Result.RulePath.First(); // What command launched the app?
switch (voiceCommandName) // Run the action specific to the command
{
case "comand1": // User said comand1
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand2": // User said comand2
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand3": // User said comand3
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
case "comand4":
rootFrame.Navigate(typeof(SpeechHandlingPage), vcArgs.Result);
break;
}
and in the OnNavigated method of the speech handling page:
SpeechRecognitionResult vcArgs = e.Parameter as SpeechRecognitionResult;
RcvdCommand = vcArgs.Text.ToUpper();
// Check for null!
string commandMode = vcArgs.SemanticInterpretation.Properties["commandMode"][0];
if (commandMode == "voice") // Did the user speak or type the command?
{
RequestHanding();
MyTextblock.Text = vcArgs.Text;
// SpeakText(audioPlayer, String.Format(" app heard you say {0}", RcvdCommand ));
// HandleNlpCommand(vcArgs);
}
else if (commandMode == "text")
{
// messageTextBox.Text = string.Format("Working on your request \"{0}\"", RcvdCommand);
// HandleNlpCommand(vcArgs);
}
When the application is not running, and is activated by voice command, the OnLaunched() method is not called. So you need to call the code that ensures the root frame is created in the OnActivated() method as well:
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();
// ... restore app state, etc.
Window.Current.Content = rootFrame;
}
this is my first time to use stackoverflow :) ,
I was working with grid template app in windows 8 store app and i wanted to add welcome page after the splash screen loaded , to do that i tried to add this statement
this.Frame.Navigate(typeof(WelcomePage));
to the OnLaunched method that was created by default with the grid template in the App.xmal.cs. after i created the Welcomepage it self and i created a button in the welcome page to navigate to the GroupedItemsPage.
My logic isn't working.
this is the default method code in the App.xmal.cs if that will help
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
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();
//Associate the frame with a SuspensionManager key
SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// Restore the saved session state only when appropriate
try
{
await SuspensionManager.RestoreAsync();
}
catch (SuspensionManagerException)
{
//Something went wrong restoring state.
//Assume there is no state and continue
}
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(GroupedItemsPage), "AllGroups"))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}
I want to enter win32 desktop from a metro app when launch the metro app (press the app's tile on metro startup screen). One way is to open a file (e.g. a TXT file) when start the metro app. I add the following code logic into OnLaunched, sometimes it can open the file and enter desktop, but sometimes, it doesn't. Could someone help me? (just create a blank app in VS2012).
async protected override void OnLaunched(LaunchActivatedEventArgs args) {
// Do not repeat app initialization when already running, just ensure that the window //is active
if (args.PreviousExecutionState == ApplicationExecutionState.Running)
{
Window.Current.Activate();
return;
}
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Create a Frame to act navigation context and navigate to the first page
// var rootFrame = new Frame();
if (!rootFrame.Navigate(typeof(MainPage)))
{
throw new Exception("Failed to create initial page");
}
// Place the frame in the current Window and ensure that it is active
Window.Current.Content = rootFrame;
Window.Current.Activate();
{
string txtfile = #"Assets\a.txt";
var file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(txtfile);
if (file != null)
{
bool success = await Windows.System.Launcher.LaunchFileAsync(file);
if (success)
{
}
else
{
}
}
}
}
BatRT allows you to execute a batch file from a metro app. This could be used to run any desktop application from a metro app. As soon as the metro app starts execute a batch file to run your desired desktop application.