Windows Phone 8.1 : how to Launch an Installed app From My app - c#

I have tried the following links
How do I launch other app from my own app in Windows Phone 8.1?
Call an external app on windows phone 8.1 runtime(not silverlight) xaml c# application
but nothing is working for me as i simply wants to launch one app for e.g. angry birds from my app using a button click.
Please Help

If the app has a registered URI, then you should be able to use Launcher.LaunchUriAsync for this. You can also find some help, here at MSDN - How to launch the default app for a URI.
Otherwise I don't think it's possible.

It works for me.
setup your app which launch from other.
add this in WMAppManifest.xaml between < /token> and < ScreenResolutions>
<Extensions>
<Protocol Name="alsdkcs" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>
add a class "AssociationUriMapper " and override the function "MapUri()"
class AssociationUriMapper : UriMapperBase{
private string tempUri;
public override Uri MapUri(Uri uri){
tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
if (tempUri.Contains("alsdkcs:MainPage?id=")){
int idIndex = tempUri.IndexOf("id=") + 3; //3 is the length of "id="
string id = tempUri.Substring(idIndex);
return new Uri("/MainPage.xaml?id=" + id, UriKind.Relative);
}
return uri;
}
}
and call them from other app.xaml.cs at this section of InitializePhoneApplication() function
RootFrame.UriMapper = new AssociationUriMapper(); // add this line only between RootFrame.Navigated += CompleteInitializePhoneApplication; and RootFrame.NavigationFailed += RootFrame_NavigationFailed;
finally call fron other app to launch an app
var success = await Windows.System.Launcher.LaunchUriAsync(new System.Uri("alsdkcs:MainPage?id="+5));
if (success){
// URI launched
}
else{
// URI launch failed
}
where "alsdkcs" is protocol name.
more details see msdn

Related

How do you launch a web authentication window within Unity for a UWP app?

I'm trying to use the Twitter Service from the UWPCommunityToolkit, which I have running as a standalone UWP (Universal Windows Platform) app, but when I import it into Unity (2017.2.0f3) as a library, it doesn't open the authentication window.
This is what shows up on the working standalone UWP app:
When in unity, it seems to go through the setup code, but not run this line properly:
var result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);
https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.Services/Services/Twitter/TwitterDataProvider.cs#L293
It just returns WebAuthenticationStatus.UserCancel, whereas on the standalone UWP, it'd return WebAuthenticationStatus.Success. Note, it also returns WebAuthenticationStatus.UserCancel on the standalone UWP app when the user clicks the close button on the pop up.
Is it possible to run WebAuthenticationBroker.AuthenticateAsync (https://learn.microsoft.com/en-us/windows/uwp/security/web-authentication-broker) in Unity? Are there any other ways to do web authentication on the Windows platform using Unity?
I've also tried TwitterKit, but unfortunately, it doesn't have support for Windows UWP (only iOS and Android).
Thanks!
LINQ to Twitter supports UWP. It has a UniversalAuthorizer that works like this:
private async void TweetButton_Click(object sender, RoutedEventArgs e)
{
var authorizer = new UniversalAuthorizer
{
CredentialStore = new InMemoryCredentialStore
{
ConsumerKey = "",
ConsumerSecret = ""
}
};
await authorizer.AuthorizeAsync();
var ctx = new TwitterContext(authorizer);
string userInput = tweetText.Text;
Status tweet = await ctx.TweetAsync(userInput);
ResponseTextBlock.Text = tweet.Text;
await new MessageDialog("You Tweeted: " + tweet.Text, "Success!").ShowAsync();
}
Check out the Samples folder for a complete listing: https://github.com/JoeMayo/LinqToTwitter

uwp close browser programmatically

I'm creating a simple news feed, it i want it can open the browser to show the details of the news, but i don't know how to close the browser , here is the code of how I open the browser,anyone can teach me how to off the browser using uwp? '
public async void test()
{
RootObject mynews = await NewsProxy.GetNews();
string website = mynews.articles[i].url;
var uriWeb = new Uri(websites);
var success = await Windows.System.Launcher.LaunchUriAsync(uriWeb);
if (success)
{
//Uri launched
}
else
{
// uri launch failed
}
}
var success = await Windows.System.Launcher.LaunchUriAsync(uriWeb);
Your code is actually telling the OS to Launch the given url and the OS in turn launches the default browser with the given URL. So you are not actually launching the browser.
In order to have full control over the browser behavior you can implement your own WebView and then use the url to navigate your WebView.
webView1.Navigate("http://www.contoso.com");
(MSDN Documentation for WebView)

Push notification for windows phone 8 for getting URI

I have developed Windows Phone 8 application and I have implemented Push Notification Service in it.
When I start Application in windows Phone Emulator it creates URI(Getting from MPNS) and send it to the Database for sending notification next time, But the Problem is that when I restart my Emulator the URI get changed, I want to keep the same URI for the Device or Emulator so how can I do that?
My code for generating the URI is
HttpNotificationChannel pushChannel;
string channelName = "TileSampleChannel";
InitializeComponent();
pushChannel = HttpNotificationChannel.Find(channelName);
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.Open();
pushChannel.BindToShellTile();
}
else
{
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
//System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
// MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
string strURI = pushChannel.ChannelUri.ToString();
(App.Current as App).phoneURI = strURI;
}
I Picked this (App.Current as App).phoneURI and Sent to Database but it get change when I restart emulator?
And sometime it gives URI and sometime it throws an exception An exception of type 'System.NullReferenceException' occurred in TileNotificationClient.DLL but was not handled in user code on this line string strURI = pushChannel.ChannelUri.ToString();
The (imho) good side of the emulator is, that you have a fresh, clean system every time you restart it.
The Notifikation uri is not guarantied to be consistent on real devices either. You should incorporate changing channel Uris in your application design.

Trying to update livetile from backgroundaudiotask in Windows Phone 8.1: "The application identifier provided is invalid"

I have a music player and would like to update the livetile with the albumart of the playing track. So each time the track changes I call a method in a seperate Windows Runtine Component. The method looks like this:
public async void CreateLivetile(string albumart, string artist, string trackname)
{
try
{
// constants
string textElementName = "text";
string imageElementName = "image";
// Create a tile update manager
var updater = TileUpdateManager.CreateTileUpdaterForApplication();
updater.EnableNotificationQueue(true);
updater.Clear();
// wide 310x150
var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage03);
tileXml.GetElementsByTagName(textElementName).LastOrDefault().InnerText = string.Format(artist + " - " + trackname);
var image = tileXml.GetElementsByTagName(imageElementName).FirstOrDefault();
if (image != null)
{
var src = tileXml.CreateAttribute("src");
src.Value = albumart;
image.Attributes.SetNamedItem(src);
}
// square 150x150
var squaredTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
squaredTileXml.GetElementsByTagName(textElementName).FirstOrDefault().InnerText = string.Format(artist + " - " + trackname);
image = squaredTileXml.GetElementsByTagName(imageElementName).LastOrDefault();
if (image != null)
{
var src = squaredTileXml.CreateAttribute("src");
src.Value = albumart;
image.Attributes.SetNamedItem(src);
}
updater.Update(new TileNotification(tileXml));
updater.Update(new TileNotification(squaredTileXml));
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
// Inform the system that the task is finished.
//_deferral.Complete();
}
}
When the method reaches this line:
var updater = TileUpdateManager.CreateTileUpdaterForApplication();
I get this error:
The application identifier provided is invalid.
This method does work fine in the app (front-end)...
There is solution:
http://social.msdn.microsoft.com/Forums/windowsapps/en-US/83498107-fe0d-4a8b-93f3-02d484983953/tileupdatemanager-throws-exception?forum=wpdevelop
Just provide ID directly:
TileUpdateManager.CreateTileUpdaterForApplication("App")
You've found a common bug in the simulator.
From one of Microsoft's blogs:
We’ve found two scenarios that cause this failure. The first is during
app development when running the app in the simulator in Visual
Studio. This error may be thrown when updating tiles. The
recommendation is to run the app under the Local Machine setting
[...].
Secondly, this failure can occur when the underlying notification
platform is not available on the user’s machine. If the notification
platform has encountered an issue that caused it to terminate, it
causes tile notification and updating to fail as well. The call to
TileUpdateManager.CreateTileUpdaterForApplication normally retrieves
the package full name, creates a notification endpoint, and performs
package and app name validation for the notification subsystem.
Problems with either of the last two steps can cause “The application
identifier provided is invalid” to be returned, generating this
exception.
See also:
updating tiles in Win 8 Metro app
Why is identifier for secondary tile invalid?
"cant-update-secondary-tile"

How to load javascript in windows 8

I am looking for a way to implement Internet explorer - a desktop version in my Winodws 8 app . This is caused by my c# application- i need to run javascript page but its impossible in metro version of IE. Is there any method to do this?
I `ll describe my problem: when i want to load html of DOM page(rendered by javascript) i cant because javascript can run (I use WebView). I tried to open this page using Desktop version and it worked perfectly. Unfortunately Metro IE10 cant show the content and my WebView too.
Thanks for help.
You can sure inject in the c# webview a javascript file:
This is the action for a button:
private async void Lamp_Click(object sender, RoutedEventArgs e)
{
Uri uri = new Uri("ms-appx:///js/injected.js");
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);
string text = await FileIO.ReadTextAsync(file); //reading content as string
var script = "(function(){" + text + "})()";
}
try
{
var result = wv.InvokeScript("eval", new string[] { script });
}
catch (Exception) { }
wv is you id name for the webview element in the xaml

Categories