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

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();
}

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??

Appium - running browser tests without clearing browser data

I'm testing a web application on Chrome, Android (real device, not emulator) using Appium. Whenever I launch a test, all browser data (bookmarks, history etc.) is deleted. Is there any way to stop this from happening?
I tried setting the noReset capability to true, but that didn't help.
Thank you in advance for any help
public static Uri testServerAddress = new Uri("http://127.0.01:4723/wd/hub"); // Appium is running locally
public static TimeSpan INIT_TIMEOUT_SEC = TimeSpan.FromSeconds(180);
public void SetUpTest()
{
if (driver == null)
{
DesiredCapabilities testCapabilities = new DesiredCapabilities();
testCapabilities.SetCapability("browserName", "Chrome");
testCapabilities.SetCapability("platformName", "Android");
testCapabilities.SetCapability("deviceName", "S(Galaxy S5)");
testCapabilities.SetCapability("noReset", true);
AppUrl = "http://www.google.com/"; //for example
driver = new RemoteWebDriver(testServerAddress, testCapabilities, INIT_TIMEOUT_SEC);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, globalTimeoutInSec));
driver.Navigate().GoToUrl(AppUrl);
}
}
Chromedriver always starts totally fresh, nothing is keeping.
There is option to re-use the existent one (using desired capability androidUseRunningApp) but unfortunately Appium any way will kill it.
Please see more details in this post

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.

Application working on emulator but crashed on phone WP8

At start I'm sorry for my English is poor. And this is the only place where i solved the problem.
I have a problem with my application. I write and test it on emulator in VisualStudnio 2012 and It work fine. But when I add aplication in WindowsPhone store and I get to phone. It crashed. I think that problem is in geolocator or something with GPS, because when i use function where my it don't use gps it work. Everywhere where i use geolocator_geopositionchanged it break down and app is terminate. in one of application page i use map control but i gave token and application id but only in class where i use map.
private void maping_Loaded(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = "id";
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = "token";
}
Do you have any sugestion or advices?
if you want watching app there is a link
http://www.windowsphone.com/pl-PL/store/app/opencaching/06bce1e1-16ef-4ebf-ac53-23b4c725f78b
I have geolocator in a few class it's one of them
Geolocator code
if (!tracking)
{
gps = new Geolocator();
gps.DesiredAccuracy = PositionAccuracy.High;
gps.ReportInterval = 100;
gps.PositionChanged += geolocator_PositionChanged;
}
else
{
gps.PositionChanged -= geolocator_PositionChanged;
gps = null;
}
tracking = !tracking;
Geoposition changed code
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
double distance = 0;
distance = point.GetDistanceTo(new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude));
string asa = Convert.ToInt64(distance).ToString();
if (asa != null)
{
Dispatcher.BeginInvoke(() =>
{
TBodleglosc.Text = asa +"m";
navi.Rotation = 180 + Kierunek(point.Latitude, point.Longitude, args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
});
}
}
Debug on your device. If that cannot repro, setup a Beta Test app and use that to distribute the app back to yourself for debugging. Sometimes signing breaks things.
I debug at lumia 920 and I have a problem with convert.toDouble
because there are was , i have . and vice versa
I think that it's connected with phone language
because in english emulator and Ertay Shashko phone who debug it yesterday it's working fine.
At now application work at phone but doesn't at emulator.
but if i change settings on location and language apps work but I can't debug because visual studio have error
It's weird .....

Debugging WP8 Native Code using a file

I'm developing a WP8 app that has some native code (runtime component).
Inside the runtime component I need to check to content of a c style array.
Because this array is not small, I thought the best I could do is write the array in a file
using fopen/fwrite/fclose;
Checking the returned value from fopen and fwrite, I can see that it succeeded.
But I cannot find the file (using Windows Phone Power Tools).
So where has the file been written?
Is there another way to dump the content of the array to a file (on the computer) from visual studio ?
I'm unfamiliar with the fopen/fwrite/fclose APIs in WP8. Which probably means it's not a whitelisted API you can use to submit your app with. It's best if you just use "Windows::Storage::ApplicationData::Current->LocalFolder" when working with IsoStore in C++. See Win8 code sample # http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700361.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1
Thanks Justin,
here's how I ended up doing it:
auto folder = Windows::Storage::ApplicationData::Current->LocalFolder;
Concurrency::task<Windows::Storage::StorageFile^> createFileOp(
folder->CreateFileAsync(L"Data.bin", Windows::Storage::CreationCollisionOption::ReplaceExisting));
createFileOp.then(
[nData, pData](Windows::Storage::StorageFile^ file)
{
return file->OpenAsync(Windows::Storage::FileAccessMode::ReadWrite);
})
.then([nData, pData](Windows::Storage::Streams::IRandomAccessStream^ stream)
{
auto buffer = ref new Platform::Array<BYTE>(pData, nData);
auto outputStream = stream->GetOutputStreamAt(0);
auto dataWriter = ref new Windows::Storage::Streams::DataWriter(outputStream);
dataWriter->WriteBytes(buffer);
return dataWriter->StoreAsync();
})
.wait();
Now compare that to what I "meant" :
FILE *fp = fopen("Data.bin", "wb");
if (fp)
{
int ret = fwrite(pData, 1, nData, fp);
fclose(fp);
}