Bluetooth api for Windows phone in Windows 8 throwing exception - windows-phone-8

A call to the Windows phone 8 bluetooth api is not working in Windows 8. I'm getting the following exception:
System.InvalidOperationException' occurred in sampleunivapp.Windows.exe but was not handled in user code
WinRT information: FindAllPeersAsync cannot be called before Start
Additional information: A method was called at an unexpected time.
code
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = string.Empty;
var peerList =await PeerFinder.FindAllPeersAsync();
if (peerList.Count > 0)
{
wpeername.Text = peerList[0].DisplayName;
}
else
{
var msg=new MessageDialog("No active peers");
msg.ShowAsync();
}

Related

Chrome API HID receive not working in Windows

I have a chromapp which sends data to PC using usb, connected as an HID device, working perfectly in Linux. While trying to do the same in windows, the app sees that the device is connected but throws an runtime error :
Unchecked runtime.lastError while running hid.receive: Transfer failed.
The hid.receive callback function is implemented as follows
var pollDevice = function() {
var size = 64;
chrome.hid.receive(connectionId, function(reportId, data) {
if (data != null) {
var dataAscii = arrayBufferToString(data);
console.log(dataAscii);
}
setTimeout(pollDevice, 1);
});
};
I am running Google Chrome Version : 52.0.2743.116 on Windows 10 Pro, Version 1607, Build 14388.0
Did someone else similar issues? Can someone help me out on this??

chrome.hid.send not sending packets

I am developing a chrome app that needs to be connected to a custom HID device.I am able to receive data from the the device.
I do have write permission on hid and usb bus.Yet there is no data received by the device.
I am successfully able to send data via hidapi in a separate program.
Can you suggest any method to check whether or not chrome.hid.send is working or not?
OS : Arch Linux
Chrome version : 46.0.2490.22 beta (64-bit)
Well the following code snippet seems to work for me : (taken from HID sample app from chrome-app-samples)
function sendHid(){
var bytes = new Uint8Array(63);
bytes[0] = 0x01;//to send 0x01 to HID device
chrome.hid.send(connectionId,0,bytes.buffer,function(){
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
else {
console.log("Sent!");
}
});
}

How to configure Non-authenticated push notification for windows phone 8 in worklight

I have configured push notification in Android and IOS, and it's works perfectly. but when I configured Non-authenticated push notification for windows phone 8 in worklight, it's not working.I follow the below MobileFirst document to run push notification for windows Phone 8:
https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-7-1/foundation/notifications/push-notifications-overview/push-notifications-in-hybrid-applications/#setupWP8
Also i want to know, for subscription based push notification, which notification is recommended for windows phone 8 i.e. Non-authenticated push or Authenticated push?
Below is my code:
adapter.js
function submitNotification(userId, notificationText){
var userSubscription = WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);
if (userSubscription==null){
return { result: "No subscription found for user :: " + userId };
}
var notification={};
notification.MPNS={};
var badgeDigit = 1;
var notification = WL.Server.createDefaultNotification(notificationText, badgeDigit, {custom:"data"});
notification.MPNS.toast={};
notification.MPNS.toast.text1 = "Toast title";
notification.MPNS.toast.text2 = "Toast content";
WL.Logger.debug("submitNotification >> userId :: " + userId + ", text :: " + notificationText);
WL.Server.notifyAllDevices(userSubscription, notification);
return {
result: "Notification sent to user :: " + userId
};
}
application-descriptor.xml
<windowsPhone8 version="1.0">
<uuid>5747-54938-fjhg-f459-844h-fhkj</uuid>
</windowsPhone8>
Please help me on windows phone 8 push notification.
++++++++++++++++++++++++++++++Update Question+++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
After adding push sender id in "application-descriptor.xml". push notification is working on windows phone8. but facing problem to receive broadcast notification on windows phone8.
broadcastAdapter.js
function sendBroadcastNotification(applicationId, notificationText) {
var notificationOptions = {};
notificationOptions.message = {};
notificationOptions.message.alert = notificationText;
WL.Server.sendMessage(applicationId, notificationOptions);
return {
result : "Notification sent to all users."
};
}
client side code in main.js:
if(WL.Client.Push){
WL.Client.Push.onMessage = function (props, payload) {
navigationFromNotification = true;
WL.SimpleDialog.show("Tag Notifications", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("Brodcast Notifications", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {
window.location.href="#/home/2";
}
}]);
}
}]);
};
}
Am I need to add anything to receive broadcast Notification on windows phone8 ?
The documentation you have linked to clearly mentions to add an empty pushSender element, and as can be seen in your code snippet from application-descriptor.xml - you did not do that. Basically, you did not configure your application to use push notifications(!).
<windowsPhone8 version="1.0">
<uuid>auto-generated by the platform</uuid>
<pushSender />
</windowsPhone8>
Authenticated or not authenticated push is not related to user-based subscription.
You can use either one. The only limitation by MS is that non-authenticated is limited to 500 messages per day, whereas authenticated is not limited (and more secure).
a) MPNS Push notifications can operate in unauthenticated or authenticated mode. In unauthenticated mode, the number and frequency of notifications allowed through the Microsoft Push Notification Service is throttled (unauthenticated push notifications are currently limited to 500 per day, per channel).
MSDN documentation.
IBM MobileFirst supports both authenticated and non-authenticated MPNS push.
b) In case of Tag/Broadcast MPNS notifications, by default the notification appears within the application tile. For the notification to be displayed when the application is in foreground or as a toast notification add the following code to the sendBroadcastNotification() method in the adapter:
notificationOptions.settings = {};
notificationOptions.settings.mpns ={};
notificationOptions.settings.mpns.raw = {};
notificationOptions.settings.mpns.raw.payload= {'payload' : notificationText};
notificationOptions.settings.mpns.toast ={};
notificationOptions.settings.mpns.toast.text1 = 'Title';
notificationOptions.settings.mpns.toast.text2= notificationText;
Refer to the TagNotifications sample for the complete code

System.UnauthorizedAccessException: Access to the path denied in wp8

I have published an App in the store and there is this weird behavior. Some users are unable to use the app as it is giving an exception
System.UnauthorizedAccessException: Access to the path "//path//filename" denied.
The stack trace is below.
1 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
2 at System.IO.File.InternalDelete(String path, Boolean checkHost)
3 at System.IO.File.Delete(String path)
The code which does this is
var filePath = String.Format(".\\TestDataSet\\{0}", "TestJson");
if (String.IsNullOrEmpty(content))
{
return;
}
File.Delete(filePath);
using (var stream = File.OpenWrite(filePath))
{
using (var writer = new StreamWriter(stream))
{
await writer.WriteAsync(content);
}
}
The App is up and running in 75% of devices. 25% of users are facing this issue.
Does it have something to do with the Windows Phone update in some of the devices ? Or the user can set device specific / app specific permissions ?

Microsoft.Smartdevice.Connectivity and Windows Phone 8, launch native apps, send input?

I've written a small .NET Console program that will launch the Windows 8 Simulator. Very straightforward:
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
var devices = connectivity.GetConnectableDevices();
ConnectableDevice connectableDevice = devices[2];
Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");
Pretty straightforward. However, what I want to do now is programmatically interact with the device. I know I can launch my own Apps by using iDevice.installApplication but what I really want to do is run a built-in app that comes with the simulator (the mail app). Can I use the SmartDevice.Connectivity libs to send touches, or launch 'hidden' apps that don't show up in the GetInstalledApplications() method? the API is sparse, and doesn't seem like a ton of developers are using this.
I've actually found a better framework than the SmartDevice framework. Inside the C:\Program Files (x86)\Microsoft XDE\8.0 folder you can find the Microsoft.XDE DLLs, which help power the Windows 8 simulator wrapper/skin, and are managed libraries that allow you to interact with the simulator. Sample code:
private static void BootViaXdeLibs()
{
var factory = new Microsoft.Xde.Wmi.XdeWmiFactory();
Console.WriteLine("Polling for virtual machines");
var virtualMachine = factory.GetAllXdeVirtualMachines(SettingsOptions.None)[2];
Console.WriteLine("Found machine {0}", virtualMachine.Name);
if (virtualMachine.EnabledState != VirtualMachineEnabledState.Disabled)
{
Console.WriteLine("Virtual Machine {0} is already running. Shutting down. ", virtualMachine.Name);
virtualMachine.Stop();
while (virtualMachine.EnabledState != VirtualMachineEnabledState.Disabled)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Starting {0}", virtualMachine.Name);
virtualMachine.Start();
while (virtualMachine.EnabledState == VirtualMachineEnabledState.Starting)
{
Thread.Sleep(1000);
}
Console.WriteLine("Sleeping before image capture to give boot time");
Thread.Sleep(30000);
//Click on the screen
virtualMachine.SendMouseEvent(new MouseEventArgs(MouseButtons.Left, 1, 295, 260, 0));
Thread.Sleep(100);
virtualMachine.SendMouseEvent(new MouseEventArgs(MouseButtons.None, 0, 295, 260, 0));
Thread.Sleep(1000);
Console.WriteLine("Saving screenshot");
//Capture Screen
var res = virtualMachine.GetCurrentResolution();
var image = virtualMachine.GetScreenShot(0, 0, res.Width, res.Height);
image.Save("C:\\image.png", ImageFormat.Png);
virtualMachine.Stop();
}