Equivalent of Session.Abandon() in Windows Phone 8 - c#

Is there an equivalent of Session.Abandon() in Windows Phone 8?
For instance, in order to create a "session" in Windows Phone, one would do the following:
PhoneApplicationService.Current.State["Username"] = username;
Now, I can simply destroy its value using:
PhoneApplicationService.Current.State["Username"] = null;
However, if I have multiple "sessions", I would have to do this for each and every one of them. Is there a method which destroys all the "sessions" in Windows Phone?

Have you tried this? State is an IDictionary and should support this method.
PhoneApplicationService.Current.State.Clear();

Related

Windows 8.1 WPF application mixerSetControlDetails returns MMSYSERR_ERROR

Edit
After modifying the NAudio source code and a little debugging, I found that the mixerSetControlDetails function, which is called when I set the Value property, returns MMSYSERR_ERROR.
Is there a way to get further information about why mixerSetControlDetails failed?
I'm also open to other ways to accomplish same thing on C#.
Original
I have some code that computes energy in voice and sets the microphone boost level according to this computed value using NAudio. I have no problem reading audio samples but when I try to set microphone boost, the program gets stuck.
I have checked the issue on Windows 7, 8, and 8.1. The problem occurs only on Windows 8.1. Interestingly when I run the program on a virtual machine with Windows 8.1 it works as expected. Can this be a permission problem?
Here is the code for setting the boost value
foreach (MixerControl mixerControl in MixerLine.Controls)
{
if (mixerControl.ControlType == MixerControlType.Volume)
{
UnsignedMixerControl volumeControl = (UnsignedMixerControl)mixerControl;
volumeControl.Value = (uint) value;
}
}
Where MixerLine is created beforehand with this code.
MixerLine = new MixerLine((IntPtr) deviceID, 0, MixerFlags.WaveIn);
It seems the mixerSetControlDetails function returns MMSYSERR_ERROR randomly (at least I couldn't find a pattern). Actually it does set the new value, just ignore the exception, or if it does not set try setting the value again. The stuck behavior was about my program, irrelevant to this error.

How to detect Windows Phone 8.1 OS version programmatically?

The question in title is not the real problem. I went through many sites and blogs and go to know that Environment.OSVersion gives you the current OS version of the phone using our app. But the problem is, There is no OSVersion under the class Environment. Please refer the screenshot for better understanding.
My question why I am not able to see the OSVersion property under Environment class? Am I missing something?
Universal/WinRT apps only work in wp 8.1, so the OS version can only be 8.1. When they make wp8.2 or wp9, they'll probably add a way to check what OS version is installed...
If you're looking for the firmware version, you can get it with:
Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
var firmwareVersion = deviceInfo.SystemFirmwareVersion;
Copied from duped question:
Windows Phone 8.1 Silverlight apps can use the .NET version APIs. There is no supported mechanism to get a version number in Universal 8.1 apps, but you can try using reflection to get the Windows 10 AnalyticsInfo class, which will at least tell you the version number if you are running on Windows 10.
Note: Checking the OS version is almost always the wrong thing to do, unless you're simply displaying it to the user (eg, in an "About" box) or sending it to your back-end analytics server for number crunching. It should not be used to make any run-time decisions, because in general it's a poor proxy for whatever-you're-actually-trying-to-do.
Here is a sample:
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)
{
Debug.WriteLine("Apparently you are not on Windows 10");
return;
}
var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo");
object versionInfo = versionInfoProperty.GetValue(null);
var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion");
object familyVersion = versionProperty.GetValue(versionInfo);
long versionBytes;
if (!long.TryParse(familyVersion.ToString(), out versionBytes))
{
Debug.WriteLine("Can't parse version number");
return;
}
Version uapVersion = new Version((ushort)(versionBytes >> 48),
(ushort)(versionBytes >> 32),
(ushort)(versionBytes >> 16),
(ushort)(versionBytes));
Debug.WriteLine("UAP Version is " + uapVersion);
Obviously you can update this to return the version etc. rather than print it to the debug console.
You cannot get the OS Version in Windows 8.1 .Check the following link for the same - https://social.msdn.microsoft.com/Forums/windowsapps/en-US/2b455331-3bad-4d26-b615-a59d0e05d0dd/how-to-get-os-version-on-window-phone?forum=wpdevelop
I found a tricky way to detect if a device is running a Windows Phone 8.1 or Windows Phone 10. I compared 3 different devices, a Nokia Lumia 925 ( wp 8.1 ) a Nokia Lumia 735 ( wp 10 ) and a Nokia Lumia 930 ( wp 10 ). I noticed that on wp8.1 there is no device info id ( it causes a not implemented exception ) but it exists on windows phone 10 on both tested devices. Morover the system firmware version format seems different between wp 8.1 and wp 10 ( the first is xxxx.xxxxx.xxxx.xxxx while the second is xxxxx.xxxxx.xxxxx.xxxxx ). Below my function:
/// <summary>
/// Indicates if this device is running a version of Windows Phone 8.1. It use a dirty trick for detecting the OS major version
/// based on the system firmware version format (8.1 is xxxx.xxxxx.xxxx.xxxx while 10 is xxxxx.xxxxx.xxxxx.xxxxx )
/// moreover, the "deviceInfo.id" is not implemented on Windows Phone 8.1, but it is on Windows Phone 10
/// </summary>
/// <returns></returns>
public static bool liIsWindowsPhone81(bool basedOnDeviceInfoId)
{
EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
bool isWin81 = false;
if (basedOnDeviceInfoId)
{
try
{
var deviceInfoId = deviceInfo.Id;
}
catch
{
isWin81 = true;
}
}
else
{
string firmwareVersion = deviceInfo.SystemFirmwareVersion.Trim();
string[] parts = firmwareVersion.Split('.');
if (parts[0].Length == 4 && parts[1].Length == 5 && parts[2].Length == 4 && parts[3].Length == 4)
{
isWin81 = true;
}
}
return isWin81;
}
I haven't had the opportunity to test this on further devices, but so far seems to work. I use it to distinguish the code for the app rating function between Windows Phone 8.1 and Windows Phone 10, that in my specific case are not UWP
Hope this helps
If your app is Silverlight based, you can use System.Environment.OSVersion.Version across Windows Phone 8.0 and 8.1 as well as Windows Mobile 10.
Here is an example of a method we utilize when determining whether to display our own opt-in dialog for geo-tracking or let the Windows Mobile 10 present its own opt-in dialog.
public static bool IsWindowsPhone8x()
{
try
{
Version version = System.Environment.OSVersion.Version;
return version.Major > 8 ? false : true;
}
catch (Exception)
{
return false;
}
}
Simply use this line to get the Application Name and Id, publisher name etc...
string name = Windows.ApplicationModel.Package.Current.DisplayName;

Does windowsphone 8 keep the unused IsolatedStorage in case of application updating?

After Updating A windows phone 8 app, will it keep the unused IsolatedStorage?
and if i change object saved in it, will it throw exceptions on users devices because of object changes doesn't saved under the key saved in the old version.
if so, how can i change/remove Edited/Unused IsolatedStorageSettings when i update a windows phone 8 application?
Isolated Storage data are preserved between updates, so it's the same IsolatedStorageSettings as in old version.
If you add/change objects in this way: settings["key"] = value; nothing wrong will happens after update. Also, you can check if some value exists or not before read it:
if (settings.Contains("key"))
{
string value = (string) settings["key"];
}

Showing different calendars in Windows Phone 7

I'm trying to get a complete list of all calendars. If I list
(new Appointments()).Accounts
I get only accounts like "Windows Live" or "Google". Actually I need a way to get the calendars and the appointments to that calendar inside the accounts. But it has to be on any account, not only the Live Account. Read only access is enough though. Is there any possibility?
If there is no chance, is this possible under WP8? Yes, I know, hardware capabilities were to high for this feature under WP7.8.
There is a method Appointments.SearchAsync which you should use. There is quite a nice example on MSDN:
Appointments appts = new Appointments();
appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = start.AddDays(7);
appts.SearchAsync(start, end, "Appointments Test #1");
Within callback function you'll have access to args.Results of type IEnumerable<Appointment>.
This is available on both WP7.1 and WP8.

Why does the WP8 Tiles example use reflection?

Use of the new WP8 Tiles uses reflection instead of instantiating and calling the methods directly as shown below.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj720574(v=vs.105).aspx
Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
shellTileType.GetMethod("Update").Invoke(tileToUpdate, new Object[] { UpdateTileData });
I'm wondering if there is a specific reason reflection is being used this situation. Is it cause the WP < 7.8 won't have a reference to the ShellTile Type and thus the VM will error? If the VM never accesses this part of the code wouldn't that be good enough?
You can target your app for one of WP7 or WP8 platfroms.
In WP7 SDK there is no FlipTileData class, so you won't be able to compele code wich uses this class.
But you can run your WP7 app on WP8 device, so you can create Wilde Tiles using reflection.
You just need to check the OS version before:
private static Version TargetedVersion = new Version(8, 0);
public static bool IsTargetedVersion
{
get
{
return Environment.OSVersion.Version >= TargetedVersion;
}
}
Otherwise, if you target your app for WP8 platform only - feel free to use FlipTileData and other classes without reflection. Here you can find the example.
In WP7 SDK there is no API for these new Tile types, they are only available in WP7.8 and WP8. So if you want to use new tile sizes on WP7.8 devices or in WP7 application running on WP8 device, you have to use reflection.
Of course in WP8 app you can use the API directly with no problems.

Categories

Resources