How to launch app from another app in Windows Phone 8.1 - windows-phone-8.1

I want to launch my app from another app in the Windows Phone 8.1 environment. I followed the instructions in MSDN, but I cannot figure out how to call the first app from the second. This is the protocol I added in the first app's manifest file:
<Extensions>
<Extension Category="windows.protocol">
<Protocol Name="myapp">
<Logo>Assets\SmallLogo.scale-240.png</Logo>
<DisplayName>my App 1</DisplayName>
</Protocol>
</Extension>
</Extensions>
This is my call from the second app, that does absolutely nothing:
private async void btn_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new System.Uri("myapp:"));
}

Follow the steps in Auto-launching apps using file and URI associations for Windows Phone 8
And you have use use a class which is derived from UriMapperBase to handle the navigation and have to set it as RootFrame.UriMapper in the App.xaml.cs
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;
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new AssociationUriMapper();
******
}

Related

How to get a storage file from camera roll in windows phone 8.1

How can I create a Windows.Storage.StorageFile from a picture in Camera Roll for windows phone 8.1? I have tried the follwing:-
try{
Windows.Storage.StorageFolder folder = Windows.Storage.KnownFolders.CameraRoll;
Windows.Storage.StorageFile file = await folder.GetFileAsync(filename);
}
catch(Exception exc)
{
MessageBox.Show(exc.Message);
}
Which is producing an Access Violation Exception.
Can someone plz tell me how to do it in windows phone 8.1?
First, you may need to declare the capability in the package.appxmanifest.
Once you’ve done this you can now use the Windows.Storage.KnownFolders class to access the Picture Library.
Here is how to get to the camera roll, you can refer to.
public async Task<IEnumerable<StorageFile>> GetFilesInCameraRoll()
{
var cameraRoll = await KnownFolders.PicturesLibrary.GetFolderAsync("Camera Roll");
return await cameraRoll.GetFilesAsync();
}
More detailed information, you can refer to Access Camera Roll in Windows Phone 8.1

Template10 - Open Browser in OnStartAsync

I implemented a toast with to open an url.
Here's the toast:
<toast>
<visual><binding template='ToastGeneric'><text>Go To bing.com</text></binding></visual></toast>
After that I added the handling to the OnStartAsync-Method:
public override Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
// navigates to Splash-Page
NavigationHelper.NavigationService = NavigationService;
NavigationService.Navigate(typeof(SplashPage));
// open the url
if (args is ToastNotificationActivatedEventArgs)
{
Windows.System.Launcher.LaunchUriAsync(new Uri("http://www.bing.com"));
}
return Task.FromResult<object>(null);
}
unfortunately the App crashes on the phone (it works like a charm on a desktop machine) every time I open the app with a tap on a notification with the following exeption (If I start the app without a tap on a notification, the normal way, it doesn't crash):
$exception {"Object reference not set to an instance of an object."} System.NullReferenceException
With the following stacktrace:
at Template10.Common.BootStrapper.<HandleResuming>d__99.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.ThrowAsync>b__6_0(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
at Windows.ApplicationModel.Core.UnhandledError.Propagate()
at Microsoft.HockeyApp.Extensibility.Windows.UnhandledExceptionTelemetryModule.CoreApplication_UnhandledErrorDetected(Object sender, UnhandledErrorDetectedEventArgs e)" string
I can't figure out the problem by myself and need some help right here.
If I remove the line with the Launch the app doesn't crash.

Windows Phone app not receiving push notification from Parse.com

I have followed this tutorial on setting up Parse push notification in a Windows Phone app. This is my code:
public App() {
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Standard XAML initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
// Language display initialization
InitializeLanguage();
// Show graphics profiling information while debugging.
if (Debugger.IsAttached) {
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are handed off to GPU with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
// Prevent the screen from turning off while under the debugger by disabling
// the application's idle detection.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
// Initialize the Parse client with your Application ID and .NET Key found on
// your Parse dashboard
ParseClient.Initialize("grpTmrClet8K35yeXg2HQKK8wl59VeC9ijH0I0dn", "os8EfSFq9maPBtDJ91Mq0xnWme8fLANhttTPAqKu");
// After calling ParseClient.Initialize():
this.Startup += async (sender, args) =>
{
// This optional line tracks statistics around app opens, including push effectiveness:
ParseAnalytics.TrackAppOpens(RootFrame);
// By convention, the empty string is considered a "Broadcast" channel
// Note that we had to add "async" to the definition to use the await keyword
await ParsePush.SubscribeAsync("testchannel");
};
}
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private async void Application_Launching(object sender, LaunchingEventArgs e) {
await ParseAnalytics.TrackAppOpenedAsync();
}
When I send a push notification from the Parse dashboard it doesn't get received. I have tried running both on the emulator (Windows Phone 8.0) and device (8.1), with app in foreground, background and closed with the same negative result.
When I use a channel like "testchannel" above and use the segment options, the channel name appears in the dropdown list of options indicating that the app is at least connecting Parse, but it just wont receive the notifications.
Hope someone can help me identify what I am missing. Thanks in advance.
If you are developing a Windows Phone 8.1 app, make sure you've enabled toast notification in the manifest file.
I don't quite understand everything about Parse just yet, but this is what works for me.
In App.xaml.cs:
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
ParseClient.Initialize("wSjuNTbtjVLRaedXvOoaf9S5cTbkuQohTulNZ2vS", "nWZMhXRet9Wotlgikb9aUdKf5GFtRiMvduw7w68z");
}
We subscribe and enable analytics OnLaunched:
protected async override void OnLaunched(LaunchActivatedEventArgs e)
//Generated codes go here
await ParsePush.SubscribeAsync("testchannel");
await ParseAnalytics.TrackAppOpenedAsync();
That would simply do the trick. You should modify the code according to your needs. Hope this helps.

How to collect application logs in windows phone 8.1?

I am new to windows phone platform.Is there anything available like logcat in android for windows for collecting logs?Thanks in advance.
Windows 8.1 introduced new classes to simplify logging. These classes are LoggingChannel, LoggingSession and others.
Here's an example:
App.xaml.cs
LoggingSession logSession;
LoggingChannel logChannel;
public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}
void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
logChannel.LogMessage("Unhandled exception: " + e.Message);
logSession.SaveToFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "MainLog.log").AsTask().Wait();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
logSession = new LoggingSession("MainLogSession");
Resources["MainLogSession"] = logSession;
logChannel = new LoggingChannel("AppLogChannel");
logSession.AddLoggingChannel(logChannel);
}
MainPage.xaml.cs
LoggingChannel logChannel;
public MainPage()
{
this.InitializeComponent();
var logSession = (LoggingSession)Application.Current.Resources["MainLogSession"];
logChannel = new LoggingChannel("MainPageLogChannel");
logSession.AddLoggingChannel(logChannel);
logChannel.LogMessage("MainPage ctor", LoggingLevel.Information);
}
I highly recommend watching the Making your Windows Store Apps More Reliable keynote during the 2013 build conference, where Harry Pierson demonstrates these new APIs in more detail (including uploading the log file to a backend server using a background task that gets executed when the phone is connected to AC power).
You can use System.Diagnostics.Debug to view the logs on Visual Studio Console Window but you won't be able to collect them later because it's only shown during debug.
I recommend the use of MetroLog, a lightweight logging system designed specifically for Windows Store and Windows Phone apps.
You can install it using NuGet
Install-Package MetroLog
Here's an quick example:
using MetroLog;
using MetroLog.Targets;
LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget());
GlobalCrashHandler.Configure();
ILogger log = LogManagerFactory.DefaultLogManager.GetLogger<MainPage>();
log.Trace("This is a trace message.");
You can find a tutorial explaining how to add it on your project at http://talkitbr.com/2015/06/11/adicionando-logs-em-universal-apps. Also there is an explanation regarding retrieving these logs.

Push Notification not received by windows phone app : Parse

I have followed all the steps given in the documentation to register for a push notification from the Parse website. (All the steps in the sense I downloaded the default project and added event handler to handle the incoming toast notification).
ParseClient.Initialize("x0uNa3Q164SVGKbH4mxZJaxWxsuYtslB5tVPj893",
"cXFv9RQAoray9xFdwdcZCHXrrkrM6KNd0WyN194H");
this.Startup += async (sender, args) =>
{
// This optional line tracks statistics around app opens, including push effectiveness:
ParseAnalytics.TrackAppOpens(RootFrame);
// By convention, the empty string is considered a "Broadcast" channel
// Note that we had to add "async" to the definition to use the await keyword
await ParsePush.SubscribeAsync("");
};
ParsePush.ToastNotificationReceived += ParsePushOnToastNotificationReceived;
and the handler
private void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
var s = new ShellToast();
s.Content = notificationEventArgs.Collection.Values.First();
s.Title = "My Toast";
s.Show();
}
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
await ParseAnalytics.TrackAppOpenedAsync();
}
When I run the app in the emulator it registers the app and I can verify it in my dashboard. But as soon as I send push notification from the website number of registered devices will be shown as 0 and the app doesnt receive the notification.
One thing to mention is this behavior is not consistent. Sometimes the app does receive the notification. Can anyone mention the reason for this or any other point I am missing?
One thing to note is that ShellToast.Show() should only be used from background task. If you call it when an app is in the foreground, toast won't be shown. http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.shell.shelltoast.show(v=vs.105).aspx
So, be sure your app is not in the foreground when you expect to see toast notification.
Firstly you will be shown toast notification only if the foreground app is not running. If your app is running when you receive push notification you have to do like:
void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>{
// do anything
MessageBox.Show("got notification");
});
}
If your app is not running the os will handle the notification properly, you dont have to do anything.