Windows Phone 8 ApplicationSettings - Get settings in Universal app - windows-phone-8

I'm upgrading windows phone 8 application. I created Universal app (Windows.Phone 8.1).
The settings in old WP8.0 application are saved in following way:
IsolatedStorageSettings.ApplicationSettings.Add("MY_SETTINGS", value);
Question:
How can i get this settings when app is upgraded to WP8.1 (Universal app).
I try the following:
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var isContains1 = localSettings.Values.ContainsKey("MY_SETTINGS");
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
var isContains2 = roamingSettings.Values.ContainsKey("MY_SETTINGS");
But no "MY_SETTINGS" are found. (isContains1, isContains2 == false):\
Many Thanks for help

LocalSettings in WP8.1 works differently than those in WP8.0 - where settings were saved in a file (after serialization). The file is __ApplicationSettings - take a look at it (via IS explorer tool) and you will see its structure - part of it is a serialized dictionary. I've made some research once, which showed that all the old files are preserved during the update - which means that the settings are still there.
Once you update your WP8.0 app to WP8.1 and you want to read your old settings, you can retrive the values from the file.

This blog post has your exact answer, including the code needed to deserialize the migrated settings file!

You can use ApplicationData.LocalSettings It would Get you the application settings container in the local app data store. here is a Dev center link in which its Described how to use it.

Related

WinRT write to home group

Is it possible to create new folder in main Windows Phone folder? I am trying to access home group as follows:
var picturesLibrary = KnownFolders.HomeGroup;
var savedPicturesFolder = await picturesLibrary.CreateFolderAsync("folderName", CreationCollisionOption.OpenIfExists);
but it ends up having error. If i specify subfolder like Pictures it works correctly.
From the msdn docs
If your app is a Windows Phone Store app, reading the value of this property raises an exception of type System.Exception.
https://msdn.microsoft.com/en-us/windows.storage.knownfolders.homegroup?f=255&MSPPError=-2147217396
May be it does not supported in windows phone.
requirment
To access the HomeGroup folder, in the app manifest, specify at least
one of the following capabilities: Pictures Library, Music Library, or
Videos Library. Learn more about these capabilities in
Access to user resources using the Windows Runtime.

IsolatedStorageSettings after application update from store

I am writing my Windows Phone 8.1 Silverlight App (NOT RunTIME framework).
I have to questions:
Which is the App manifest file for Windows Phone 8.1 Silverlight? WMAppManifest or Package.appxmanifest? as my project contains both
I created a method in Mainpage of application which detects that is it the first time this application is running or not. If it is first time execution of this app, registry of 120 keys (IsolatedStorageSettings.ApplicationSettings) is created and app moves to WelcomePage.If the execution is not the firsttime, means user has opened this app before, it skips the registrycreation method and directly goes to homepage.
When I upload this version 1 of app to store and users install and use it. What when I add more keys to registrycreate method in version 2 and upload version 2 to store. How will be those new keys get created? Even, when user updates the app, the registrycreation method will never run.
The "Silverlight" app manifest is WMAppManifest.xml, but you still need to include the "RT" manifest Package.appxmanifest and, if you ever use any of the RT namespaces that require certain capabilities, you should check those capabilities in the Package.appxmanifest too. Eg "Internet (Client & Server)" if you are using things like Windows.Networking.BackgroundTransfer.
You'd need to add some code to check if the information or information structure has changed every time the app is run (or resumed), so that in the event of an update (and change in the keys), they get added, even if your "first run" code doesn't fire. Make sense?
If you know the keys numbers will always get bigger then watching the key count will work. You could also include a key with the version so you can tell which version the data was created with.
You can use Windows.Storage.ApplicationData instead of IsolatedStorageSettings in Windows Phone Silverlight 8.1. ApplicationData supports versioning with the ApplicationData.SetVersionAsync method so you can change the data format safely when you update the app.
Either way, when the app runs check if the data's version is the latest that the app knows about. If not then run your setup and migration code to add the new keys and replace the out-of-date ones.
The data version doesn't have to match the app version (you may update the app's version without changing the data). You can compile a data version constant into the app's data handling code and bump it whenever you change the data format.

Sync data between devices with windows universal app

I am new with universal windows app development, and I am looking for some way to share data (on each device database) created on windows phone app with windows app and vice versa, I don't want involve a webserver to manage this, the only exception maybe is the user's onedrive, I'm think if it's possible the windows app (rt or desktop) version run a little service to handle this over wi-fi? or some way tho backup and restore database using onedrive?
You should use the roaming app data. I don't know how big your database is. But to maintain integrity you could serialize each table into JSON and store it. It's easy as pie:
var roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
roamingSettings.Values["exampleSetting"] = "Hello World";
If that isn't enough for you, you can even store a file inside the roaming folder:
var roamingFolder = Windows.Storage.ApplicationData.Current.RoamingFolder;
StorageFile database = await roamingFolder.CreateFileAsync("mydb.sqlite",
CreateCollisionOption.ReplaceExisting);
Read more here:
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh700362.aspx
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh464917.aspx#roaming_app_data

Air App will not read local text file using openAsync/readUTFBytes on user (non-admin) mode

I am running an Air App I did for the desktop, from the actual installed executable already deployed in the machine (Not from Flash Pro / Flex dev. environment). For some reason the app will not read a text file stored in the same application folder unless I run my app as administrator from the OS.
When I run the app as admin, or within the development environment it works fine. Maybe this is related to some security issue? I read the adobe air documentation, and this should work...
I am using openAsync/readUTFBytes on user as shown here:
var continueGamesConnection:FileStream();
var continueFile:File = new File(File.applicationDirectory.resolvePath("continueGames.txt").nativePath.toString());
continueGamesConnection.addEventListener(Event.COMPLETE, openSavedGames);
continueGamesConnection.openAsync(continueFile, FileMode.UPDATE);
function openSavedGames(event:Event):void
{
continueGamesConnection.removeEventListener(Event.COMPLETE, openSavedGames);
var content:URLVariables = new URLVariables();
var loadedContent:String = new String();
loadedContent = continueGamesConnection.readUTFBytes(continueGamesConnection.bytesAvailable);
content.decode(loadedContent);
variableX = content. variableX
//etc, etc.
continueGamesConnection.close();
}
By the way, I have also, tried using FileMode.READ, and others, and it still gives me the same problem. Only works if ran on admin mode or from the dev. environment.
It's very frustrating, I tried reading other posts without any luck... What solutions do people use for this kind of problem?
I have seen that you can set the app to run as admin somehow, and I guess that could work. However, this should work just fine, since it doesn't seem to violate any of the security APIs of Air. Seems like an overkill. But even so, how do I do that?
You help is greatly appreciated!
Typically for security reasons, applications do not have write permissions to the File.applicationDirectory.
It is recommended you use File.applicationStorageDirectory instead as that is the most appropriate place to save user data (such as a save game file).
Alternatively, you could also let the user browse to a directory with the FileReference class which may or not have permission.
Assuming that you are using a Windows SO, the problem that you have is about user access restrictions to folders C:\Program Files and C:\Program Files (x86) and there is nothing you can do from Flash or AIR to solve it. You could modify you security settings by right click on the folder or you should simply avoid using the app folder to store anything

How to test Windows Phone 8 app update, migrate IsolatedStorageSettings

I have completely rewritten one of my Windows phone 8 app. I use IsolatedStorageSettings to store user specified settings in both "old" and "new" versions of my app. In my new app version I just convert the old settings structure to new one.
Now I want to test the app update case. So far I have tried the following.
Build "old" and "new" xap files using VS (same app id and publisher id).
Install the old xap using WP Power Tools
Save some settings in app, check using WP Power Tools that the settings are saved to __ApplicationSettings
Update the app xap file using WP Power Tools
Check that the __ApplicationSettings is still there with "old" data
Launch the new app, __ApplicationSettings is now empty and all old data has gone.
What im doing wrong? Ho should I test the app update case, and how to keep the old __ApplicationSettings in place?
Is there some id's (?) which are now different in my old and new app and the platform thinks that the old __ApplicationSettings does not belong to new version and deletes it? Im using completely new namespace in my new app.
UPDATE
Im still struggling with this issue, how how to keep old isolated storage settings (__ApplicationSettings). In the file itself there is references to my app namespace. For example I have saved collection of MyCollectionItem's, in the __ApplicationSettings I find line:
System.Collections.Generic.List`1[[MyOldApp.MyModels.MyCollectionItem,
MyOldApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]],
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxx
Now as my new app uses completely new namespace, this is not working?
Also I noticed that when I first time save something to IsolatedStorageSettings with my new app, the old settings (__ApplicationSettings) are erased.
Any idea how to migrage the IsolatedStorageSettings from old app to new one, as basically my new app is completely new app.
Theres two part to this question,
Using persistent storage like IsolatedStorage to share data between two versions.
testing the versions upgrade keeping data.
This might help you with 2nd part,
submit a Beta version of your older app.
install it and add data > will be stored in isolated Storage
submit a beta for new version, while submitting choose Add New, DO NOT replace.
you will get notification on mobile that the new version is available, choose to upgrade.
after installation, you should see your data.
lengthy process, but worked for me. hope it helps