How can we detect Windows 10 in Windows Phone 8.1 app? - c#

my app (developed in Windows Phone 8.1 RT environment) uses OpenFilePicker which allows me to choose image and capture an image, it works great however when I deployed this app on a Windows 10 device, this function just allowed me to pick an image from the library. I thought about a solution, writing a small code block which can help me to detect the version of the OS like this
#if WINDOWS_PHONE_APP
//codes
#endif
But I don't know exactly what I need to do, so please help me!

Read this link:
Windows Store Apps: Get OS Version, beginners tutorials (C#-XAML)
it purpose a simple solution to check is OS has Windows 10 features with reflection:
var analyticsInfoType = Type.GetType("Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime");
var versionInfoType = Type.GetType("Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime");
if (analyticsInfoType == null || versionInfoType == null)
{
// That's not Windows 10
}

Related

BarcodeScanner.GetDefaultAsync() is always returning null

I'm trying to create a simple application in UWP for a Zebra device (Model TC700J) running Windows 8, in which I make use of the built in barcode scanner.
From what I've found, there's plenty of Zebra tutorials for accessing the scanner when programming on Android, but none for Windows due to the fact that Microsoft provide their own generic barcode scanner API found in the Windows.Devices.PointOfService namespace.
The code I currently have looks something like this:
BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
claimedScanner = await scanner.ClaimScannerAsync();
}
The problem is that the if statement never evaluates to true as the GetDefaultAsync method always returns null.
Over here there was an answer that seemed to work, stating that it depends where the GetDefaultAsync method is placed. I've tried to put it in all of the suggested places though and to no avail.
There is another method, BarcodeScanner.FromIdAsync() which returns a barcode based on the string representation of that barcode scanner's id sent as a parameter, but I'm not sure that'd be valid here as the barcode scanner is built into the device.
Looking at Zebra's site, TC700J seems to be model number of Windows 10 Mobile IoT Enterprize OS.
And the platform is ARM(Qualcomm snapdragon), not Intel x86/x64.
TC70 / TC75 Touch Computer Series
https://www.zebra.com/us/en/products/mobile-computers/handheld/tc7x-touch-computer-series.html
TC70x Operating System (TC700J) Windows 10 Mobile IoT Enterprise v1.13.02 Release Notes
https://www.zebra.com/us/en/support-downloads/software/release-notes/operating-system/tc70x-operating-system-v1-13-02--release-notes.html
For example, if your Zebra device is old hardware and Windows Phone 8/8.1 is running, Windows Phone does not seem to support Windows.Devices.PointOfService namespace.
It is described in the comment of the following article.
Windows Phone 8.1: Scan Barcodes using Camera
If your Zebra device can update to Windows 10 Mobile IoT Enterprise, please check it after doing it.
If you can update it, you can use the barcode scanner sample for Windows 10.
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BarcodeScanner
If your device is running on Windows 8 for x86, since Windows.Devices.PointOfService namespace is supported from Windows 8.1, you need to change the OS to Windows 8.1/10 if possible.
In that case you can use following, or above(for Windows10) sample.
Barcode scanner sample for Windows 8.1
https://code.msdn.microsoft.com/windowsapps/Barcode-scanner-sample-f39aa411
If you can not update it, please get the software and documentation for using BarcodeScanner from the vendor on Windows (Phone?) 8.
Seems the usage of Async method wasn't quite right.
Try below code:
BarcodeScanner scanner;
ClaimedBarcodeScanner claimedScanner;
scanner = await BarcodeScanner.GetDefaultAsync();
if (scanner != null)
{
claimedScanner = await scanner.ClaimScannerAsync();
}
More details:
https://learn.microsoft.com/en-us/dotnet/csharp/async
https://msdn.microsoft.com/en-us/magazine/jj991977.aspx?f=255&MSPPError=-2147217396

C#, how make a if loop statement for windows version like windows 8 or windows 10?

i have write automation code for product which i'm currently working on and some functionality is various according to windows version. to tacks those functions i planned to have if loop for windows local and if you have better idea then this means pls update it
Note: i'm beginner Automation testing
You can get the system/environment to get the value for the windows build and version .
For Windows 8.1+ you can no longer use the OSVersion (it will always show Windows Version 8). Instead you should include an App Manifest and write different scripts based on the targeted environment.
You can read from regsirty through code and do specific action what you intended.
Say for ex:
Registry key you can find here:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion and then look for "ProductName"
You can open registry information by giving regedit.exe in run (windows+r)
var reg =
Registry.LocalMachine.OpenSubKey(#"SOFTWARE\Microsoft\WindowsNT\CurrentVersion");
string productName = (string)reg.GetValue("ProductName");
if(productName.StartsWith("Windows 10"))
{
}
else
{
}
//Get Operating system information.
OperatingSystem os = Environment.OSVersion;
//Get version information about the os.
Version vs = os.Version;
if (vs.Major == 10 && vs.Minor == 0) // Test flow for WINDOWS 10 environment
{
}
else if (vs.Major == 6 && vs.Minor == 3) // Test flow for WINDOWS 8.1 environment
{
}
else // Test flow for WINDOWS 7 and 8 environment
{

Detect headphones in windows phone 8.1

For my Windows Phone 8.1 RT app I need to detect whether headphones are plugged in.
I found this questions which answers this issue for Windows Phone 8.0 and Windows Phone 8.1 Silverlight apps:
Windows Phone - Audio Endpoint Device
It tried this code in the code-behind of my main view (actually copied from http://developer.nokia.com/community/wiki/How_to_detect_the_audio_path_(headset_connection)_on_Windows_Phone):
AudioRoutingEndpoint currentAudioRoutingEndpoint = AudioRoutingManager.GetDefault().GetAudioEndpoint();
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged_Handler;
and the handler:
private void AudioEndpointChanged_Handler(AudioRoutingManager sender, object args)
{
var audioEndPoint = sender.GetAudioEndpoint();
switch (audioEndPoint)
{
case AudioRoutingEndpoint.Default:
{
//default audio devide
break;
}
case AudioRoutingEndpoint.Earpiece:
{
//Earpiece
break;
}
case AudioRoutingEndpoint.Speakerphone:
{
//Speakerphone
break;
}
case AudioRoutingEndpoint.Bluetooth:
{
//Bluetooth
break;
}
case AudioRoutingEndpoint.WiredHeadset:
{
//WiredHeadset
break;
}
case AudioRoutingEndpoint.WiredHeadsetSpeakerOnly:
{
//WiredHeadsetSpeakerOnly
break;
}
case AudioRoutingEndpoint.BluetoothWithNoiseAndEchoCancellation:
{
//BluetoothWithNoiseAndEchoCancellation
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
If I run this code I get this exception:
System.UnauthorizedAccessException was unhandled by user code HResult=-2147024891
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I guess this is because the needed capabilities (ID_CAP_VOIP and ID_CAP_AUDIOROUTING) are missing.
Now my problem is that in my Windows Phone 8.1 RT app there is only a package.appxmanifest and no WMAppManifest.xml and it seems I can't define these capabilities anymore.
Please note that I really have no WMAppManifest.xml in my project as it would be in a Windows Phone 8.1 Silverlight project (there are in fact both available).
Is there a way to add these capabilities for my WP 8.1 RT app?
Or is there another way to detect headphones in Windows Phone 8.1 RT I just didn't found?
I would really appreciate any help!
EDIT: changed Windows Phone 8.1 xaml to Windows Phone 8.1 RT
So two things:
This feature is usable only during during a VOIP call, and only in the background task for the VOIP call - see the comments on this answer.
These VOIP features are only available to Windows Phone 8.1 Silverlight apps, and again, only in VOIP background tasks. So no luck for WinRT 8.1 or Universal apps. The MSDN documentation is here (A list of other features not available in Phone 8.1 WinRT here)
So.. you probably can't do what you want to do on Windows Phone (unless you're building a VOIP app).
What feature are you trying to implement with this? Maybe there is an alternative.
in WP8.1 Runtime you can create a xml file WindowsPhoneReserveAppInfo.xml with below code:
<?xml version="1.0" encoding="utf-8" ?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
<SoftwareCapabilities>
<SoftwareCapability Id="ID_CAP_VOIP" />
</SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>
It work fine. Good luck!

Checking WMAppPRHeader.xml in XNA with Windows Phone 7

I'm developing a game for Windows Phone 7.1 with XNA framework.
I know there is a way to prevent piracy for Windows Phone 7 (and 8.0, 8.1) - checking if the file "WMAppPRHeader.xml" exists in app directory.
I'm using this code:
try
{
Stream stream = TitleContainer.OpenStream("WPAppPRHeader.xml");
if (stream.CanRead)
{
stream.ReadByte();
stream.Close();
}
}
catch
{
//file read error, it means it was hacked
}
When use this code and upload my game to Windows phone marketplace as a "Beta" app, it works great. File "WPAppPRHeader.xml" is readable from my game and the test is passed.
But, when upload the same XAP in Windows Phone marketplace as a public app, this code fails and my game thinks that it was hacked (I'm checking this somewhere in the middle, so microsoft testers doesn't event recognise that something is wrong and my game succesfuly passes certification).
So, what am I doing wrong? Why the same code, the same XAP is working when it's Beta, and not working when it's Public?
I still don't know why TitleContainer.OpenStream is working in beta and not working in public market, but here is the code, that works in public market:
System.Xml.Linq.XDocument.Load("WPAppPRHeader.xml");

DeviceNetworkInformation.IsCellularDataEnabled always returns false

I recently installed the Windows Phone 8.1 emulators to try some existing apps out on them and ran into this problem: DeviceNetworkInformation.IsCellularDataEnabled (in the Microsoft.Phone.Net.NetworkInformation namespace) is always returning false.
public void UpdateDataEnabled()
{
_dataEnabled = DeviceNetworkInformation.IsCellularDataEnabled
|| DeviceNetworkInformation.IsWiFiEnabled;
}
I know the connection is actually working because I'm still able to perform HTTP requests. If I run this same exact code in the 8.0.x emulators I don't have any problems.
I also tried updating the project and all libraries to Windows Phone Silverlight 8.1 apps to see if that would resolve the issue and no luck. I checked all the capabilities and ID_CAP_NETWORKING was still checked as well.
The emulator is tested and working if I write a pure Windows Phone 8.1 XAML app using Windows 8 method of obtaining network status. It's just not working for my Silverlight apps.
I was under the impression that Windows Phone Silverlight apps should continue to function on Windows Phone 8.1 devices. Am I overlooking something?
I have the same problem and i did what verdesrobert and Rishabh876 suggested. Its only emulator problem so i add condition to check out if app is running on emulator
public bool IsNetworkAvailable()
{
if (DeviceNetworkInformation.IsNetworkAvailable)
{
if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
{
return true;
}
else if ((DeviceNetworkInformation.IsWiFiEnabled || DeviceNetworkInformation.IsCellularDataEnabled) && NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None)
{
return true;
}
}
return false;
}
I dont like that workaround much so if anyone has better solution let me know.
It seems that the WP8.1 emulator is giving that information only to WP8.1 apps.
I'm pretty sure that the 7.1 apps will work properly on WP8.1 Devices.

Categories