How to execute a background task only for once in windows phone 8.1 universal app - windows-phone-8.1

In my application after first login/registration I need to download data from server this will take some time. And user can quit the application while data is loading. So I need to download the data in background process. I know I can use backgorund application/Class and register this class in windows phone application but this is only for one time. Is there any other way to do so without creating backgourd task for this?

Maybe this will help,
You're looking for BackgroundDownloader and DownloadOperation in the Windows.Networking.BackgroundTransfer namespace.
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
MSDN Windows.Networking.BackgroundTransfer
Background Transfer Sample Project (Windows Universal)

Related

How to open my electron program when a link (like myprogram://a/a) is clicked in a web browser

I want to transfer information from my website to my electron program by using a link that has some data in it (like myprogram://data). But can't seem to find any info on the internet about this. Any help would be gladly appreciated.
Thanks!
You need to register your app as a protocol handler using app.setAsDefaultProtocolClient
app.setAsDefaultProtocolClient("myprogram")
On Windows, when the "myprogram://data" link is clicked, a new instance of your application will be launched and the arguments will be included in process.argv
Use app.requestSingleInstanceLock if you don't want multiple instances of your app to be running
On macOS, you can get the arguments using the open-url event

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.

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!

MissingManifestResourceException on Windows Phone 8.1 with .resx resources

I'm developing a Windows Phone 8.1 app that also targets Android(Xamarin)
As ever I added my string resources(.resx) on a PCL and referenced them on my launcher project to use it on my views, this all works fine on WP 8.1 silverlight but on the WinRt when I configure the project to release and run it on a device, for some reason I always get a MissingManifestResourceException. I've tried every solution for this problem out there without any success.
Note that on the emulator everything works fine, when the solution configurator is set to Debug it also works on both device and emulator. The only combination here is device and Release.
The app source code is on Github.
I was able to create a simple project to replicate this issue, basically it is a WP 8.1 app and a PCL project with the embedded resources, Download Link
Anyone has any ideas?
EDIT: After making some more testing I tried running an old Windows 8.1 app that I've done with the same localisation model and the same issue appeared so it seams to be a tool issue and not a configuration issue, since the Windows 8.1 app is on the market and everything went fine back there.
Our team ran into a similar issue which was tracked down to the runtime and not the PCL, WinRT component, or application package. That is, the resources exist within the PCL assembly, within the application package resources.pri file, but just cannot be found at runtime.
There is an active Microsoft Connect report here:
https://connect.microsoft.com/VisualStudio/feedback/details/991028/issue-using-resx-files-on-winrt-apps-windows-phone-and-windows
Our workaround was for the WinRT component to inject into each generated Resources class of each referenced PCL our own derived ResourceManager which redirected the call to the WinRT ResourceLoader instead. I've written a blog post that describes that workaround:
http://blogs.msdn.com/b/philliphoff/archive/2014/11/19/missingmanifestresourceexception-when-using-portable-class-libraries-in-winrt.aspx
I got to the bottom of this today. While bundling the app package, resources in dependencies that are not for a language being used by the app are stripped out. To prevent this from happening, add the following assembly-level attribute to your application.
using System.Resources;
[assembly: NeutralResourcesLanguage("en")]
I had the same behaviour. Today I created a new PCL Library (with another name) and copied the resx file to this project. I modified all references and everything just works fine in my WinRt (Windows Store) App now!
There was the string 'resources' in the portable class library name. Perhaps this was the problem!
I am able to reproduce this issue launching DVD sample and unfortunately in my project. I have an WP Silverlight 8.1 project registering a Windows Runtime Component Background Task and both of them using a Portable Class Library sharing some common localized strings as resources (.resx), among other things. The exception is thrown from Background Task when calling any property to get strings on generated .Design.cs class (only Release + Device).
In order to fix this I tried, without success, to use directly ResourceManager and/or to add .resx files directly into the Background Task.
I ended-up porting needed strings to .resw files and use the new "WinRT preferred" way via Windows.ApplicationModel.Resources.ResourceLoader in the Background Task project.
Seems to me that ResourceManager is not compatible with Windows Runtime anymore in release.
This is not necessary an answer, but is better than nothing since I do not have 50 reputation points for a comment.

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.