How to store user data in window phone 8 app? - windows-phone-8

Please help me how to store user data in window phone 8 application?
I have a plan to develop an application on windows phone 8 which allow user create xml file to store their private data. The question is how to store user data on window 8.1 phone. After search solution, i know that
+ Isolated Storage can store data but it just small data for application
+ Store data on SD card is read only.
So, is there any other way to store data?
Thank and sorry about my english skill!

ApplicationData (LocalFolder on WP8 or LocalFolder and RoamingFolder on WP8.1) is designed for what you are trying to do. The ApplicationSettings themselves are better for small pieces of data, but apps can save files of any size which the phone has room for in the LocalFolder.
See Accessing app data with the Windows Runtime on MSDN for details. While the docs target Windows Runtime apps, the ApplicationData and StorageFile API are available to Silverlight apps on Windows Phone 8 and later.
Additional Usings:
using System.Xml.Serialization;
using Windows.Storage;
using System.IO;
Code:
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile saveFile = await localFolder.CreateFileAsync("data.xml", CreationCollisionOption.ReplaceExisting);
using (var ras = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
{
Stream stream = ras.GetOutputStreamAt(0).AsStreamForWrite();
XmlSerializer serializer = new XmlSerializer(typeof(List<Book>));
serializer.Serialize(stream, data);
}
If you need more structured data than XML then you can store a SQLite database in the local folder. If you need more space than is reasonable for an app to store on the device then you'll need to move it to a web service. Azure Mobile Services is a good place to do that. You can call such a service from a Windows Phone Silverlight app, but the wizards will generate Universal apps.

Related

Get Device Model in windows Phone 8.1 Runtime

is there a way to retrieve friendly device model in windows phone 8.1?
EasClientDeviceInformation a = new EasClientDeviceInformation();
String b = a.SystemProductName; // RM-994 not lumia 1320
this Api doesn't return device friendly name.
No way to get a friendly name like Lumia 1320 directly from the API, you need to use https://github.com/ailon/PhoneNameResolver to convert the name from API (RM-994) to the friendly name.

How to get the Application Process ID in Windows Phone 8.1 Store Apps

I am developing a Windows Phone 8.1 Application and there is a need to get the Application Process ID from code. Any API with which I can get that?
You can use GetCurrentProcess followed by DuplicateHandle (and later CloseHandle) but I'm curious what you need it for... there's not much you can do with it in a Store app so maybe this won't complete your scenario.
Finally got the solution.
The Dll's for Desktop apps and Phone apps are different though the function names will be same.
When tried to import Kernal.dll lib in WIn Phone 8.1 and used p/invoke code, an exception, DllNotFoundException will be thrown. Instead in Win Phone 8.1 instead use "api-ms-win-core-processthreads-l1-1-1.dll"
To get the process ID in Win Phone 8.1 :
1)Create binding to WIN32 lib:
[DllImport("api-ms-win-core-processthreads-l1-1-1.dll", CharSet = CharSet.Unicode, ExactSpelling = false, PreserveSig = true)]
internal static extern uint GetCurrentProcessId();
2)Call the function:
uint id= GetCurrentProcessId();
For the complete set of Win Phone 8 supported API's see the MSDN link:
https://msdn.microsoft.com/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs

how to get my device token in nokia lumia 630

Basically I am PHP developer! and now I want to implement the push notifications for windows phone! So for this I have refereed many blogs and also started implement on this! but for demo purpose how I can get my device token and device specific type of my phone that having Windows 8.1 OS.
Is any GUI tool for getting this.
If you need the Device Token as follows-
Byte[] DeviceArrayID = (Byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
string UniqueDeviceID = Convert.ToBase64String(DeviceArrayID);
Debug.WriteLine("Device ID - " + UniqueDeviceID
Also, if you need help regarding push notifications in Windows Phone apps, follow this link-
http://msdn.microsoft.com/en-us/library/windows/apps/hh202967%28v=vs.105%29.aspx
It also has a project for a simple webpage which can send notification to your device for testing purposes.
The following should work
object DeviceUniqueID;
byte[] DeviceIDbyte = null;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out DeviceUniqueID))
DeviceIDbyte = (byte[])DeviceUniqueID;
string di = Convert.ToBase64String(DeviceIDbyte);
The above code will give you the device ID. You can use the string di to pass the Device ID to your web service to provide the user with push notifications.

How to use Windows Phone MediaElement with an IStorage file

Within Windows Phone 8 I have a solution whereby I am capturing a video and saving it to local storage using the new WPRT Windows.Storage APIs.
When I want to playback the video using a MediaElement control I appear to be stuck as it doesn't support playback from local storage (only isolated storage).
The code I am using is:
public async void MethodName(IStorageFile file){
var stream = (await file.OpenReadAsync()).AsStream();
VideoPlayer.SetSource(stream);
VideoPlayer.Play();
}
Yet when I run it I receive an exception "Stream must be of type IsolatedStorageFileStream".
I've also attempted to set the Source to a URI pointing to the file's location property, and following typical local storage URI convention - but this gets ignored.
Has anyone come across a solution to this?
Isolated Storage and Local Storage are the same location on the phone.
It looks like you need to use the Isolated Storage APIs rather than the new-fangled Windows Runtime ones in this case.

How to prevent lost save data when upgrade app on WP8 using cpp

cpp has no IsolatedStorageSettings or IsolatedStorageFile.
so i simply using "FILE" and "fopen" to store a game data.
but when i reinstall or upgrade the apps using "Xapdeploy" or debug with vs.
the save data will lost.
so how can i mark it is as a IsolatedStorageFile.
I mean when I upgrade the app, the file will not deleted by system.
You need to save data in the LocalFolder (new name for Isolated Storage) for it to be persisted.
There are Windows Runtime APIs you can use from C++/CX for this which are probably the best way to go (look for StorageFolder and StorageFile in particular), especially if you want to stay portable with Windows Store apps.
However if you want to use fopen the main issue is that this takes a char[], not wchar_t[] file name that is used by the rest of the platform. To get around this you will need...
void SaveToFile()
{
// get local folder (= isolated storage)
auto local = Windows::Storage::ApplicationData::Current->LocalFolder;
auto localFileNamePlatformString = local->Path + "\\game.sav";
FILE* pFile;
auto f = _wfopen_s(&pFile, localFileNamePlatformString->Data(), L"w");
auto res1 = fprintf(pFile, "123456789");
auto res2 = fclose(pFile);
}