API call to check if running in emulator wp7 - windows-phone-7

Is there a method I can call to see if I am currently running in the emulator vs. running on an actual physical phone?
I need to run some code a bit differently when I am in the emulator (I have a mock gps location service).

You can get this from Microsoft.Devices.Environment.DeviceType

if (System.Environment.DeviceType == DeviceType.Emulator)
{
}
Hope that helps

For wp 7.5 Mango sdk, it has moved to the namespace Microsoft.Devices
if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
{
//Do Stuff
}

Related

HTTPS status code 0 while accessing IBM Watson API through Hololens

credentials = new Credentials(tokenOptions, _serviceUrl);
if(credentials != null) Debug.Log("Credentials is not null!");
// Wait for tokendata
while (!credentials.HasIamTokenData())
{
Debug.Log("In the while loop"); // INFINITE LOOP ON Hololens
yield return null;
}
I get an infinte loop in the above code. This is in Watson.cs
It works well in Unity editor. This issue occurs when deployed into Hololens. I checked the RESTConnector.cs file from Watson SDK, I am getting a HTTPS status code 0, but I get status code 200 for Unity editor. I am not sure why this is happening. If its a firewall issue, how do I fix it in Hololens?
To enable the network capability of the device, you need to enable [InternetClient] under Publishing Settings/Capabilities. This tutorial shows the specific explanation of these capabilities: Capability. And check Unity guidance for capability setting:Universal Windows Player settings.
In addition, according to the experience of previous cases([WSA] ISNETWORKERROR ALWAYS RETURN TRUE WHEN RUNNING AN UWP APP ON X86 ARCHITECTURE(https://issuetracker.unity3d.com/issues/wsa-isnetworkerror-always-return-true-when-running-an-uwp-app-on-86x-architecture)) ,a few specific versions of unity will make the project get some network issues after the project is built. Therefore, if the issue still occurs after enable [InternetClient], please provide the version of unity that you are using.

Reflection failure when attempting to access Microsoft.Phone.Media.Extended

I am developing one Flash Light application in Silverlight for windows phone 8. Currently
I am deeply stuck in one issue for the use of "Microsoft.Phone.Media.Extended" assembly. Flash Light Application for Windows phone 7 is already live in Windows Phone Marketplace and it is working very fine for Windows Phone 7 but it is not working for Windows Phone 8 because of "Microsoft.Phone.Media.Extended" dll.
After converting WP7 app into wp8 and run then I got this type of error message:
Could not load file or assembly 'Microsoft.Phone.Media.Extended,Version=7.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e' or one of its dependencies. The system can not find file specific."
According to following link for Windows Phone-specific features:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206947(v=vs.105).aspx
If you were using reflection to access the API in this assembly, because they were not publicly exposed, your app may fail on a Windows Phone 8 device. Remove the calls to this assembly and use the publicly exposed media API.
I an not understanding how to use publicly exposed media API. I used Microsoft.Phone.Media.Extended using reflaction in Windows Phone 7. Is there any direct method for accessing Microsoft.Phone.Media.Extended in Windows Phone 8 or other way to solve this?
Thanks.
==========================================================================
Edited Question:
Hi,
As per the thread, we used "VideoTorchMode" enumeration to make flashlight ON. As per that, I used AudioVideoCaptureDevice class using Windows.Phone.Media.Capture namespace with following code:
var objDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolution(CameraSensorLocation.Back).First());
objDevice .SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
I want to keep the flash light on but without capturing video. So, i have not initialized video capture code. The issue is, i don’t have WP8 yet and in simulator i am not able to test this.
Can any one confirm that once i put this code, my app will work as Flashlight-X where light will be on without blinking and also it will not get crashed in WP8.
Thanks
Microsoft.Phone.Media.Extended is a private API in WP7 that wasn't meant to be used by 3rd party developers. That API doesn't exist or works on WP8.
For WP8 flashlight use the AudioVideoCaptureDevice known property of VideoTorchMode=On. Also, make sure to handle failures like exceptions or devices that don't have a Camera Torch by showing a white screen.
Here's a code sample that turns on the camera flash on my Lumia 820 and Lumia 920:
var sensorLocation = CameraSensorLocation.Back;
try
{
// get the AudioViceoCaptureDevice
var avDevice = await AudioVideoCaptureDevice.OpenAsync(sensorLocation,
AudioVideoCaptureDevice.GetAvailableCaptureResolutions(sensorLocation).First());
// turn flashlight on
var supportedCameraModes = AudioVideoCaptureDevice
.GetSupportedPropertyValues(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchMode);
if (supportedCameraModes.ToList().Contains((UInt32)VideoTorchMode.On))
{
avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
// set flash power to maxinum
avDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchPower,
AudioVideoCaptureDevice.GetSupportedPropertyRange(sensorLocation, KnownCameraAudioVideoProperties.VideoTorchPower).Max);
}
else
{
ShowWhiteScreenInsteadOfCameraTorch();
}
}
catch(Exception ex)
{
// Flashlight isn't supported on this device, instead show a White Screen as the flash light
ShowWhiteScreenInsteadOfCameraTorch();
}
Make sure to add the required capabilities and requirements to your WP8 app when using the camera torch (ISV_Camera, Microphone, and ID_REQ_BACK_Camera).
What about getting this assembly from somewhere and adding it to your XAP directly (try asking on XDA developers)? This might work, if it's signed and not requiring any special capabilities.
If you use the new API to "record" a video, then using the VideoTorchMode enumeration might do just want you want to create a "flashlight" effect.

How to check/switch the airplane mode programmatically in Windows 8?

I have to check if the Airplane Mode is enabled in Windows 8 and maybe switch its state. I am currently working on a C# .NET 4.0 Windows Forms application but the answers in this question shouldn't be limited by that.
Unfortunately, there isn't a programmatic way for Metro apps to change the airplane mode in Windows 8. It is against the Metro guidelines for an application to go outside its sandbox and modify system settings like this without user permission (see the discussion at http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1ad10725-b1b8-4723-b2c3-861900809e02).
Now, you may be able to figure out the status by using some of the functionality in the Windows.Networking.NetworkOperators namespace. Specifically, check out the MobileBroadbandRadioState and NetworkDeviceStatus enumerations.
Or, you could prompt the user to make the change by explaining how to access the setting using Windows Key + I, Change PC Settings, Wireless, Airplane Mode.
Here is a code snippet to get the NetworkConnectivityLevel which will likely give you what you need to know. I don't know if there is a way to change it. I would doubt it because you would need to also provide a way to pick a network to connect to.
public static NetworkConnectivityLevel GetNetworkConnectivityLevel()
{
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
var ncl = NetworkConnectivityLevel.None;
if (profile != null)
{
ncl = profile.GetNetworkConnectivityLevel();
}
return ncl;
}

will httpnotificationchannel.open() return uri and other informations when i run my windows phone apppicatin in an emulator?

Iam developing a windows phone application that makes use of windows phone push notification service. I know that we use will httpnotificationchannel.open() to open a notification channel with mspn. my question is will httpnotificationchannel.open() return uri and other informations when i run my windows phone apppicatin in an emulator? Is it necessary that i run this application in a windows phone?
Yes, this will work in the emulator.
It would have also been quicker to try than write your question.

How to get current location in Windows Phone 7 on Emulator

I am new in Windows Phone 7. I want to develop an application that tells current position (lat long) of device and highlight the current position in bing map that works on emulator because I dont have device for testing. Any help.
Thanks in advance.
Have a look at this http://create.msdn.com/en-us/education/catalog/article/GPS-Emulator
CodePlex has a FakeGPS utility (just a .cs file).
I just hard-code a known location:
if (location == GeoCoordinate.Unknown)
{
// Use Palo Alto if we're running in the emulator.
location_string = "&latitude=37.47&longitude=-122.12";
}

Resources