Background task registration hangs in UWP with GattCharacteristicNotificationTrigger - c#

I'm trying to use an in-process background task to get notifications of a Bluetooth LE device. However, the following code hangs at the last line and does not return:
var bldr = new BackgroundTaskBuilder();
bldr.Name = guid.ToString("N");
var trigger = new GattCharacteristicNotificationTrigger(ch);
bldr.SetTrigger(trigger);
bldr.Register();
Getting the notifications of the device works when using the event-based model in the application. Also, registering the task with a TimeTrigger works, so the declaration in the app manifest is ok.
The computer runs the Creators Update, but the UWP is set to require the Anniversary update as a minimum.

We've had the same issue with UWP app on windows 10 mobile. It was resolved after we had updated windows 10 mobile to build 10.0.15230.0.

This hang on Register issue for GattCharacteristicNotificationTrigger was identified and fixed thanks to this question. The fix was released in build 15228 as a servicing build to the Creator's Update of the OS.

Related

UnknownError Running ApplicationTrigger only if called while in background

With the new anniversary update sdk i have decided to change my background audio to use the new api. Everything works except that i need to make network calls when a track ends to get the next track or next playlist (8tracks.com app).
The new api allows network connectivity for buffering and downloading the song but after that the network connectivity is gone. At the bottom of this explanation it says that i will need an ApplicationTrigger to make those calls.
So I set one up and it's used in the foreground and background. When the song ends MediaPlayer.MediaEnded is triggered and then ApplicationTrigger.RequestAsync(); is called. The backgroundtask works fine if the app is in the foreground but if its in the background the await ApplicationTrigger.RequestAsync(); returns UnknownError. I have noticed that it will work fine if i'm debugging but if i'm not then the error occurs. Is it not possible to trigger an ApplicationTrigger from the new background audio api?

WebAuthenticationBrowser.AuthenticateAsync() kills the UWP app

I have a universal Windows 10 app where I use
var token = await WebAuthenticationBrowser.AuthenticateAsync(...)
to authenticate user against facebook. It all works fine in a common scenario when it's just the foreground app. However when I add a BackgroundMediaPlayer, start music playback and communication between foreground and background, calling
var token = await WebAuthenticationBrowser.AuthenticateAsync(...)
actually kills my foreground app. When user finishes the authentication in the broker, he is taken back to the app - but it was killed and is re-instantiated. This of course means that awaiting AuthenticateAsync() doesn't produce any results, because it's a new instance of the app.
I would understand this behavior when calling WebAuthenticationBrowser.AuthenticateAndContinue() which was introduced in WP8.1, but this API has been deprecated in UWP.
So my questions are - is this expected behavior (app being killed and relaunched)? If so, how do I get the token from WebAuthenticationBroker during app relaunch?
Here is a sample project to reproduce (with exact steps in a txt file): https://t.co/XtmESd9o5r
Here is a video running the sample (first launch the broker without BackgroundMediaPlayer running, then with it running): http://youtu.be/VcZXBOTiD1Y
I started a conversation about this in twitter: https://twitter.com/lancewmccarthy/status/685152844849262593 but so far the only help I got was to "check the activation kind" with this link: https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.activationkind.aspx.
The link describes activationKind has "WebAuthenticationBrokerContinuation", but
1) that's only for Windows Phone, not Windows 10
2) when you run the sample, you will never receive it. Only "Launched", with previousExecutionState "Terminated"

Exception only in one PC, in others work fine

I have an exception only in one PC, in others all work fine, anyone know wher it is comming from?
dditional information: Requested Windows Runtime type
'Windows.Media.Capture.MediaCapture' is not registered.
This exception is showing only in modern style apps (windows strore app) in windows 8.1. In WPF or Windows Form apps camera works fine. Code is fine, because in other pc work great:) i install system one more time, but the exception still showing up.
Looking at Microsoft's Windows Universal Samples (https://github.com/Microsoft/Windows-universal-samples/blob/e13cf5dca497ad661706d150a154830666913be4/Samples/SpeechRecognitionAndSynthesis/cs/AudioCapturePermissions.cs#L35) shows following piece of code
try
{
// Request access to the microphone only, to limit the number of capabilities we need
// to request in the package manifest.
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
settings.MediaCategory = MediaCategory.Speech;
MediaCapture capture = new MediaCapture();
await capture.InitializeAsync(settings);
}
catch (TypeLoadException)
{
// On SKUs without media player (eg, the N SKUs), we may not have access to the Windows.Media.Capture
// namespace unless the media player pack is installed. Handle this gracefully.
var messageDialog = new Windows.UI.Popups.MessageDialog("Media player components are unavailable.");
await messageDialog.ShowAsync();
return false;
}
So you have to install "Media player components".
I just had this issue with Windows 10. I had installed the N edition, but it looks like since it is missing Media Player, the classes related to MediaCapture are also missing.
As Hans Passant mentioned, the MediaCapture class was not registered in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId.
I reinstalled Window 10 (not the N edition) and now the class is registered.

Toast notification in windows 8.1 app

i am facing a weird problem. I am using Windows phone 8.1 silverlight and Windows universal link for toast notification. I am able to get the toast notification in Windows Phone app it is nearly same way in Windows 8.1 as mentioned in the link. But toasts are not comming in Windows 8.1 part.
Steps :-
1 -> I have enabled the Toast from Package.appxmanifest file.
2 -> Then i have added this code in App.Xaml.cs in on_launched event as mentioned
It is showing the registeration successful as mentioned in the link
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
var result = await hub.RegisterNativeAsync(channel.Uri);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
3 -> Now i send the notification from back end(Hub is working in case of phone mpns notification).
public static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var toast = #"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
await hub.SendWindowsNativeNotificationAsync(toast);
}
Question : -
Do you guys have a clue why it is not working in Windows 8.1 or what i am missing. This is the simplest example i am going through. Any help is appreciated.
Edit :- This is something interesting.
When i tried to send the notification from azure portal. From DEBUG tab of My-NotificationHub and from here i choose WNS toast then it showing an error.
Error - The token obtained from the token provider is wrong
but when i tried to send MPNS notification then there is no error. as i already mentioned it is working for WP 8.1 silverlight MPNS toast.
What could be the cause of this error ?
Toast will not work on simulator, as stated in the MSDN documentation:
Note When testing toast notification code functionality through
Microsoft Visual Studio, you must use either the Local Machine or
Remote Machine debug setting on a Windows x86, x64, or Windows Runtime
machine. You cannot use the Visual Studio Simulator debug function
option—your code will compile and run in the Simulator, but the toast
will not appear.
Source: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh868254.aspx
If I remember correctly on Windows 8 the toast notifications did not work when I was using the simulator. I had to deploy my Windows 8 application on my computer and not the simulator for me to be able to see toast notifications.

How to use C# to check if WUA is set to "Install updates automatically (recommended)?"

We have a server running a 6 day job that just reset, because Windows Update Agent (WUA) automatically rebooted the machine to install updates.
I would like to alter my C# app to warn the user if this setting is on in the future, so we don't end up suffering from random reboots, which forces a restart of said 6-day job, wasting 4 days of CPU time.
Does any know if it is possible to check within WUA that "Important Updates" is set to "Install updates automatically (recommended)", within C#?
There is an API for the Windows Update Agent (WUA), its general use is described at:
Install Windows Update Using C#
Here is the C# code:
// See http://techforum4u.com/entry.php/11-Install-Windows-Update-Using-C
var auc = new WUApiLib.AutomaticUpdatesClass();
if (auc.Settings.NotificationLevel ==
AutomaticUpdatesNotificationLevel.aunlScheduledInstallation)
{
Console.Write("{0}Warning W20120307-1107. Windows Update Agent (WUA) is capable of rebooting the PC automatically. Recommend switching this off for the duration of this 6-day batch process.\n", NPrefix());
}
After adding c:\WINDOWS\system32\wuapi.dll, if you get a compile error, see Interop type cannot be embedded.
Note that this approach will only work on Windows 7, add a try/catch around it to prevent a crash on Windows XP. See the forums for how to get it working on XP (you have to reference WUA version 1, WUA for Windows 7 is version 2).

Categories

Resources