worklight windows 8 get device name - windows-8

I need to obtain device name (the "computer Name") in worklight app for environment Windows 8.
It seems that WL.Device class can't help in Windows 8 (not Phone) environment.
Any help will be appreciated!
Thanks,
f.

There is no relation between WL.Device and what you're looking for.
In Windows 8 you need to use the WinJS API.
Try the following and inspect the JavaScript Console in Visual Studio:
function wlCommonInit() {
getHostName();
}
function getHostName() {
var hostNamesList = Windows.Networking.Connectivity.NetworkInformation.getHostNames();
for (var i = 0; i < hostNamesList.length; i++) {
var entry = hostNamesList[i];
if (entry.type === Windows.Networking.HostNameType.domainName) {
console.log(entry.displayName);
}
}
return null;
}
Source: http://caioproiete.net/en/get-the-network-machine-name-in-a-windows-store-app/

Related

Does Microsoft Band SDK support a UWP app on windows 10 iot pulling data from the Band?

I want to pull sensor data from the band using a UWP app on windows 10 iot raspberry pi. The app runs perfectly when running on windows 10 machine however, when running on windows 10 iot, it shows errors.
The execution breaks in an auto generated code in file App.g.i.cs:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();
};
#endif
In call stack it shows:
FFM.exe!FFM.App.InitializeComponent.AnonymousMethod__5_1(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) Line 53 C#
Line 53 is of the auto generated code:
if (global::System.Diagnostics.Debugger.IsAttached)global::System.Diagnostics.Debugger.Break();
Debug output shows following:
Exception thrown: 'System.NotImplementedException' in mscorlib.ni.dll
The band is able to connect to windows 10 iot Raspi but as soon as there is code that asks for user consent to access heartrate sensor data, the above errors start showing.
Following is my code to get user consent. Much of it is from the band SDK Documentation:
private async void connect()
{
//Get a list of paired bands
IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync();
string band_name = pairedBands[0].Name;
if (band_name.Length > 0)
{
bandName.Text = "Band Name is: " + band_name;
try
{
fwVer.Text = "Will try to connect to band";
IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]);
fwVer.Text = "Connected to Band";
fwVersion = await bandClient.GetFirmwareVersionAsync();
hwVersion = await bandClient.GetHardwareVersionAsync();
fwVer.Text = "Firmware Version is " + fwVersion;
hwVer.Text = "Hardware Version is " + hwVersion;
string band1v = "9";
if (hwVersion.Equals(band1v, StringComparison.Ordinal))
{
// Do work with Version 1 of the band
bandVer.Text = "Band is Version 1";
//User consent check to use heartbeat sensor data
if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() != UserConsent.Granted)
{
//Get user consent
await bandClient.SensorManager.HeartRate.RequestUserConsentAsync();
}
if (bandClient.SensorManager.HeartRate.GetCurrentUserConsent() == UserConsent.Granted)
{
//DO work
}
else
{
hrConsent.Text = "Access to HeartReat sensor is denied";
}
}
else //Its a 2nd version of band
{
//Do work with version 2 of the band
bandVer.Text = "Band is Version 2";
}
}
catch (BandException ex)
{
//handle a band connection exception
fwVer.Text = "Could not connect to above band";
}
}
else
{
bandName.Text = "No Available Bands";
}
}
Following are the libraries I am using:
using System;
using System.Threading;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Microsoft.Band;
using Microsoft.Band.Sensors;
using Microsoft.IoT;
using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
When the application calls RequestUserConsentAsync() the Band SDK displays a dialog message to the user to obtain that consent. However, it appears that Windows.UI.Popups.MessageDialog is not yet supported by Windows IoT Core (see unavailable API list).
That may be the cause of the exception.

How to trigger Cortana Programmatically?

Is there a way to use VoiceCommand methods used to programaticlly trigger Cortana as if the Cortana has registered "Hey Cortana" to begin listening?
I had this same question, but for Windows 10. Found a solution: on Windows 10, you can trigger Cortana with Win + C key stroke combination. To get this working programmatically, you would need interop with the Win32 SendInput method. Fortunately there is a NuGet package Windows Input Simulator, that does just this:
Install-Package InputSimulator
With that installed I was able to trigger Cortana from a WPF app using:
var sim = new InputSimulator();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_C);
It is not possible the closest you can get is using something like this:
async static void LaunchCortana(bool untrusted, string searchText)
{
// The URI to launch
string uriToLaunch = #"http://www.bing.com/";
searchText = "search?q=" + searchText.Replace(" ", "+");
var uri = new Uri(uriToLaunch + searchText);
// Set the option to show a warning
var options = new Windows.System.LauncherOptions();
options.TreatAsUntrusted = untrusted;
// Launch the URI with a warning prompt
var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);
if (success)
{
// URI launched
}
else
{
// URI launch failed
}
}
or
await Launcher.LaunchUriAsync(new Uri("bing://home"));
It works in Windows Phone 8.x only and utilizes the fact that Cortana disables Bing.com , but you can't use it to launch Cortana commands. It will just starts a Web search.

connect to windows phone 8 using console application

I am very new to windows phone development. I want to develop an app that will be launched when I connect my windows 8 phone to my laptop. I was following this tutorial (http://justinangel.net/WindowsPhone7EmulatorAutomation) and was able to connect to my windows 7 phone/emulator but I am not able to connect to my windows 8 phone or emulator. Is there any other way to connect to windows 8 phone?
Please let me know if there is any possible solution for this,
Thank you
I didn't get a chance to update this blog post yet. Delvis Gomez (A colleague on of mine) has updated the final code sample and OKed distributing it freely. I'll update that blog post for WP8 in the future, but in the meanwhile here's a pretty well documented code snippet on how to automate the WP8 Emulator.
Also, make sure to add a reference to the new DLLs needed like Microsoft.SmartDevice.MultiTargeting.Connectivity.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using System.Reflection;
// Libraries needed to connect to the Windows Phone X Emulator
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
using System.Globalization;
using System.Collections.ObjectModel;
namespace AutomatedUnitTestDriver
{
class Program
{
static void Main(string[] args)
{
MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
// Get a connectable device for a specific Device ID (from the CoreCon datastore)
string deviceId = "5E7661DF-D928-40ff-B747-A4B1957194F9";
ConnectableDevice connectableDevice = connectivity.GetConnectableDevice(deviceId);
Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");
// Connect to the Device
Console.WriteLine("Connecting to Device...");
IDevice iDevice = connectableDevice.Connect();
Console.WriteLine("Done!");
// Check if the application is already install, if it is remove it (From WMAppManifect.xml)
Guid appID = new Guid("{b6635769-b7ac-41a5-915d-5a7b0ae34481}");
if (iDevice.IsApplicationInstalled(appID))
{
Console.WriteLine("Uninstalling application...");
iDevice.GetApplication(appID).Uninstall();
Console.WriteLine("Done!");
}
Guid productId = appID;
Guid instanceId = appID;
string applicationGenre = "NormalApp";
string iconPath = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\ApplicationIcon.png";
string xapPackage = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\AutomatedUnitTests.xap";
// Install the application
Console.WriteLine("Installing the application...");
IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
Console.WriteLine("Done!");
// Launch the application
Console.WriteLine("Starting the application...");
remoteApplication.Launch();
int startStopWaitTime = 1000; // msec
int executionWaitTime = 180000; // msec
// Note that IRemoteApplication has a 'IsRunning' method but it is not implemented.
// So, for the moment we sleep few msec.
Thread.Sleep(startStopWaitTime);
Console.WriteLine("Done!");
// Allow application to complete
Console.WriteLine("Application is running! Waiting few seconds...");
Thread.Sleep(executionWaitTime);
try
{
IRemoteIsolatedStorageFile remoteIsolatedStorageFile = remoteApplication.GetIsolatedStore();
string sourceDeviceFilePath = (object)Path.DirectorySeparatorChar + "TestResults.trx";
string targetDesktopFilePath = #"C:\Share\LatestAPI\TestCode\Automated\AutomatedUnitTests\Bin\Debug\" + "TestResults.trx";
remoteIsolatedStorageFile.ReceiveFile(sourceDeviceFilePath, targetDesktopFilePath,true);
}
catch (Exception exception)
{
Console.WriteLine("Exception \'" + exception.Message + "\' reading file from device.");
}
// Terminate application
Console.WriteLine("Terminating the application...");
remoteApplication.TerminateRunningInstances();
Thread.Sleep(startStopWaitTime);
Console.WriteLine("\nDone!");
// Disconnect from the emulator
Console.WriteLine("Disconnecting Device...");
iDevice.Disconnect();
Console.WriteLine("\nDone!");
}
}
}
I had trouble implementing the accepted solution because I was missing the references for these namespaces:
Microsoft.SmartDevice.Connectivity.Interface
Microsoft.SmartDevice.MultiTargeting.Connectivity
Here's where I found them:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
Microsoft.SmartDevice.Connectivity.Interface\
v4.0_11.0.0.0__b03f5f7f11d50a3a\
Microsoft.Smartdevice.Connectivity.Interface.dll
and
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\
Microsoft.SmartDevice.MultiTargeting.Connectivity\
v4.0_11.0.0.0__b03f5f7f11d50a3a\
Microsoft.Smartdevice.MultiTargeting.Connectivity.dll
Note that these paths, especially the v4.0_11.0.0.0__b03f5f7f11d50a3a part, may be different on your system. Add references to these DLLs in your project, and everything should work properly.

Can the Windows 8 Live SDK use another Microsoft Account other than the current user?

Using the Windows 8 Live SDK you can have a user give you permission to their Microsoft Account. With this you can get their name and photo and more. But using the Live SDK appears to require the user of the app to use the same Microsoft Account as whoever is signed into the current session of Windows 8.
In some scenarios, using a different account is very legitimate.
I have simple sign-in working like a charm! This uses the same account.
I can't find a way to do use another. Is it possible?
You can call Logout after Init and before LoginUser.
Here's the code for javascript:
function LiveLogin(){
WL.init("<<Your clientID goes here>>");
if (WL.canLogout()) {
WL.logout(function () {Callback(callback);});
}
else{
Callback(callback);
}
}
function Callback(){
WL.login({ scope: ["wl.signin", "wl.basic", "wl.emails"] }, function () {
var session = WL.getSession();
// do stuff with your session
});
}
And this is for C#:
LiveAuthClient liveAuthClient = new LiveAuthClient();
List<string> scopes = new List<string>();
scopes.Add("wl.signin");
scopes.Add("wl.basic");
scopes.Add("wl.emails");
LiveLoginResult loginResult = await liveAuthClient.InitializeAsync();
if (liveAuthClient.CanLogout)
{
liveAuthClient.Logout();
}
loginResult = await liveAuthClient.LoginAsync(scopes);
It worked for me.
I hope this is what you are looking for.

How to detect the IsolatedStorage Used Space in Windows Phone

As per the title, how can I determine the used IsolatedStorage space in a Windows Phone Application?
You can know available free space and the used space.
try
{
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
Int64 curAvail = store.AvailableFreeSpace;
var used = store.Quota - curAvail;
}
}
catch (IsolatedStorageException)
{
// TODO: Handle that store could not be accessed.
}