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.
Related
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();
******
}
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.
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.
While I´ve been trying to make the basic notification hub tutorial work on my Windows Phone solution with the following code
var channel = HttpNotificationChannel.Find("MyPushChannel3");
if (channel == null)
{
channel = new HttpNotificationChannel("MyPushChannel3");
channel.Open();
channel.BindToShellToast();
}
channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
{
var hub = new NotificationHub("http://messaging-ns.servicebus.windows.net/messagingt", "---MY CONECTION STRING---");
await hub.RegisterNativeAsync(args.ChannelUri.ToString());
});
I get a NotificationHubNotFoundException in the await line with the following message
HTTP request failed.
HTTP Details:
Status: 404
Reason: Not Found
Full content: 404No service is hosted at the specified address..TrackingId:2e4b1100-18de-4b24-bbec-68516ddc3b60_G4,TimeStamp:2/2/2014 1:30:23 AM
I tried a number of options for the first parameter of the NotificationHub constructor called "notificationHubPath" with no luck to get my app registered. Anyone has faced this error in the past. Unfortunately there are not enough documentation in how does this constructor works in MDSN.
Thanks
When creating the NotificationHub type object, try by passing just the hub name with the connection string, not the whole address:
var hub = new NotificationHub("messagingt", "---CONECTION STRING---");
I had the same issue, and after close/open VS2013, restart PC and change Wifi/3g connection it worked again like before... strange, i suppose that was a internet connection issue.
you can use fiddler to show more information, i forgot in my case...
Hi I'm trying to save a file from a Java Webstart Application.
public class Main {
public static void main(String[] args) {
try {
FileSaveService fos = (FileSaveService) ServiceManager.lookup("javax.jnlp.FileSaveService");
//open Dialog
FileContents fc = fos.saveFileDialog("c:/data", null, new ByteArrayInputStream("Hallo Welt".getBytes()), "name.txt");
System.out.println("FileContents: " + fc);
} catch (UnavailableServiceException e) {
System.err.println("***" + e + "***");
} catch (IOException e) {
System.err.println("***" + e + "***");
}
//wait a minute
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.exit(0);
}
}
Everything works except that the dialog that comes up looks like a "open" file dialog, not like a "save" file dialog:
Any help would be appreciated.
The File-Open-dialog is necessary. You first need to let the user choose where to save the data. Thus a previous call to openFileDialog is absolute necessary for a jnlp-application. You are not allowed to directly save to a specific location like c:
If you follow the mentioned link (http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#FileSaveService) you should be successful.
EDIT:
for clarification.
Saving via javax.jnlp.FileSaveService does exactly need one call. For instance calling saveFileDialog() like this should be sufficient:
fss.saveFileDialog(null, null, new ByteArrayInputStream("Hallo Welt".getBytes() ), "newFileName.txt");
The necessity of one User-Dialogue is due to the anonymizing nature of jnlp, where your application should not get any hint about the user-filesystem.
However, I have to admit, that this was not your question.
Your main trouble comes from the java app everytime presenting the "open-dialogue" instead of the "save-dialogue".
This should not happen! If I may humbly assume from your snippet where you call fos.saveFileDialog: did you just initialize fos by the FileOpenService instead of the FileSaveService?
More details on the FileSaveService can be found here: http://docs.oracle.com/javase/7/docs/jre/api/javaws/jnlp/javax/jnlp/FileSaveService.html
This seems to be fixed in JRE bersion 1.7.0_21-b11 Java HotSpot(TM) 64-Bit Server VM
And there it is: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=2227257