WinRT write to home group - windows-runtime

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.

Related

Best approach to monitor download progress with OneDrive API on WP8.1?

I have a WP8.1 app using the new OneDrive API. I use the C# SDK provided, I get therefore something like this:
var dlStream = await Connection.DownloadStreamForItemAsync(mNode.ItemReference(),
StreamDownloadOptions.Default);
file = await folder.CreateFileAsync(fileName,
CreationCollisionOption.ReplaceExisting).AsTask();
fileStream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStream();
var v=dlStream.CopyToAsync(tn.FileStream);
I have not tried it yet, but it seems to be the right way to do it. My concern now is "how to monitor the transfer progress and status?"
Knowing that the DownloadStreamForItemAsync method does something like this:
response = await GetHttpResponseAsync(request);
var responseStream = await response.GetResponseStreamAsync();
I have thought about using a timer, and each second check the stream length, but
I don't know if it is the right approach of if there is an alternative way
I don't know if this may not create some cross-thread errors for the stream
How to detect a transfer failure ?
I guess one of the approaches would be to re-write partially the OneDrive SDK portable project, target only WinRT projects and use Windows.Web objects instead of System.Net, but it seems to be some work for an unsure result.
Any help? :)
You can use the LiveConnectClient class inside the Live SDK instead of downloading the file as a stream and saving it to a file.
Use the BackgroundDownloadAsync(string path, Uri downloadLocation) method to download a file
Begins downloading a file from Microsoft OneDrive to a Windows Phone
isolated storage. [Windows Phone only]
The file download should continue even if the app that starts the file
download quits or is suspended.
Subscribe to the BackgroundDownloadProgressChanged event
Raised at indeterminate times while a file is downloading from Microsoft OneDrive to Windows Phone isolated storage. [Windows Phone only]
Hope it helps!

WinRT: What happens when file is shared via file extension?

I'm recently looking into the file-sharing features of Windows Phone 8.1. One possibility is, to do this via file extensions. My question is, how exactly my app gets access to a launched file that it registered to handle.
I know that in WP8 this was done with a URI and a file token (https://msdn.microsoft.com/en-us/library/windows/apps/jj206987%28v=vs.105%29.aspx), but since the SharedStorageAccessManager class is not available anymore, I guess that it must be done different in 8.1.
So: What happens on "OS-level" in Win8.1/WP8.1 when an app is launched via a file extension, and how does the target-app actually get the launched file?
Thanks in Advance!
The app can register as a file handler in its Package.appxmanifest. Openthe manifest designer in Visual Studio, go to the Declarations tab, and add a File Type Associations declaration. You'll be prompted to fill out the details.
The app's Application.OnFileActivated method will be called with the launched StorageFiles in the FileActivatedEventArgs.Files property.
See How to handle file activation and the Association Launching sample for documentation and walkthroughs.
At a system level this all gets stored in the registry and when the launcher is called on a file the shell looks up the association then uses COM (or historically command line parameters or DDE) to launch or connect to the app registered for the file type. The details are hidden from Windows Runtime apps but are more directly exposed to desktop apps on Windows. See File type and URI associations model Implementing a Custom File Format

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

Windows Phone 8 ApplicationSettings - Get settings in Universal app

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.

Downloading Multiple Files from SkyDrive with Live 5.3

I'm trying to download one or more files from SkyDrive using the Windows Phone emulator. I'm pretty new at the Live SDK and I'm lost following these pages:
multiple file download using SkyDrive API
https://msdn.microsoft.com/en-us/library/live/hh826531.aspx#downloading_files
They both use methods and classes not provided in Live SDK 5.3 (more specifically, client.DownloadCompleted and LiveDownloadCompletedEventArgs).
You must be using Windows Phone 8.0 SDK. DownloadCompleted and LiveDownloadCompletedEventArgs are part of the Microsoft.Live namespace on WP7.1.
In Windows Phone 8.0 DownloadAsync() is used with the await keyword. You can use it with or without progress notification.
Sample:
var result = await client.DownloadAsync(path); // path will be file id followed by '/content'
var stream = result.Stream;