I have a Windows Phone 8.1 app in the store. Now I have created an uwp update. My question is:
If I load an update of the app into the store and an user does this update. Is the app just overwritten or deinstalled and then new installed? And are the saved settings in ApplicationData.Current.LocalSettings deleted?
thx newone
TL;DR; - It preserves data in LocalFolder and LocalSettings when updating from WP8.1 Runtime to UWP (tested with mobile on device with Insider preview - Fast ring).
I've run similar test, like the last time:
I've published a Beta version of the App - WP8.1 Runtime.
After successful installation on the Phone, I've created a file in LocalFolder and set value in LocalSettings (see code below),
I've submitted an update - went to Store, selected the App, clicked Update then Packages, after a while, browse your files and chosen the new generated appxbundle (I have not deleted the old WP8.1 package), save and submit.
After some time my Phone is notified that there is an update for the App - I click update
After successful installation, I see that it's a new App, I click my special button to check LocalFolder and value in LocalSettings - I see that there are old values from WP8.1 version.
Code for buttons used to test:
private async void Generate_Click(object sender, RoutedEventArgs e)
{
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.txt");
await FileIO.WriteTextAsync(file, "Something inside");
}
private async void CheckFile_Click(object sender, RoutedEventArgs e)
{
try
{
StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync("test.txt");
string text = await FileIO.ReadTextAsync(file);
await new MessageDialog($"File exists = {text}").ShowAsync();
}
catch (Exception) { await new MessageDialog("File desnt exists").ShowAsync(); }
}
private void GenerateSetting_Click(object sender, RoutedEventArgs e) => ApplicationData.Current.LocalSettings.Values["CHECK"] = "Test value";
private async void CheckSetting_Click(object sender, RoutedEventArgs e)
{
if (ApplicationData.Current.LocalSettings.Values.ContainsKey("CHECK"))
await new MessageDialog($"Setting exists = {ApplicationData.Current.LocalSettings.Values["CHECK"]}").ShowAsync();
else await new MessageDialog("Setting doesn't exist").ShowAsync();
}
Related
I tried to get all the music files into listbox and play the selected file.
The below code is what i did to play music but unfortunately it doesn't play. Can anyone tell me what the mistake is?
private async void button1_Click(object sender, RoutedEventArgs e)
{
StorageFolder folder = Windows.Storage.KnownFolders.MusicLibrary;
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
foreach (var file in files)
{
MusicProperties music = await file.Properties.GetMusicPropertiesAsync();
listBox2.Items.Add(music.Title);
}
}
private async void listBox2_Tapped(object sender, TappedRoutedEventArgs e)
{
try
{
StorageFolder folder = Windows.Storage.KnownFolders.MusicLibrary;
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
if (files.Count > 0)
{
var file = files[listBox2.SelectedIndex];
mediaElement1.Source = new Uri(files[listBox2.SelectedIndex].Path);
textBlock1.Text = files[listBox2.SelectedIndex].Path;
mediaElement1.Play();
}
}
catch(Exception ex)
{
textBlock1.Text = ex.Message;
}
}
Instead mediaElement1.Source = new Uri(files[listBox2.SelectedIndex].Path); you need use the code bellow:
var fileStream = await file.OpenReadAsync();
mediaElement.SetSource(fileStream, file.ContentType);
You need to use BackgroundMediaPlayer with background task.
MSDN
You can write apps for Windows Phone 8.1 that play audio in the background. This means that even after the user has left your app by pressing the Back button or the Start button on their device, your app can continue to play audio.
Scenarios for background audio playback include:
Long-running playlists The user briefly brings up a foreground app to select and start a playlist, after which the user expects the playlist to continue playing in the background.
Using task switcher The user briefly brings up a foreground app to start playing audio, then switches to another open app using the task
switch. The user expects the audio to continue playing in the
background.
I'm pretty new on Windows Phone 8.1 development and what I'm currently trying is recording a video and store it on the Windows Phone. However, I don't have any idea how that can be done. I have some code excerpt below which is the code executed when the start/stop record button is pressed. The code is taken from an example.
My questions:
How _videoFile can be saved to the VideoLibrary?
Preferably I would like the program to execute a method when recording is stopped. How I get the video filename inside this method?
private async void OnCaptureVideoButtonClick(object sender, RoutedEventArgs e)
{
if (!_capturingVideo)
{
//BtnStartStop.Content = "Stop";
StartAppBarButton.Icon = new SymbolIcon(Symbol.Stop);
_capturingVideo = true;
_videoFile = await TestedControl.StartVideoCaptureAsync(KnownFolders.VideosLibrary, "capture.mp4");
CapturedVideoElement.Visibility = Visibility.Visible;
IRandomAccessStreamWithContentType stream;
try
{
stream = await TryCatchRetry.RunWithDelayAsync<Exception, IRandomAccessStreamWithContentType>(
_videoFile.OpenReadAsync(),
TimeSpan.FromSeconds(0.5),
10);
}
catch (Exception ex)
{
#pragma warning disable 4014
new MessageDialog(ex.Message, "Error").ShowAsync();
#pragma warning restore 4014
return;
}
CapturedVideoElement.SetSource(stream, _videoFile.ContentType);
}
else
{
StartAppBarButton.Icon = new SymbolIcon(Symbol.Camera);
_capturingVideo = false;
#pragma warning disable 4014
await TestedControl.StopCapture();
#pragma warning restore 4014
}
}
Using the await keyword, StartVideoCaptureAsync is called asynchronously.
So the next line of code will be executed only once this asynchronous task is finished.
It means that the line of code below (and all the next ones):
CapturedVideoElement.Visibility = Visibility.Visible
will be executing at the end of the recording.
So if you need to execute a method after the recording is done, you can just put it after the call of StartVideoCaptureAsync.
I am learning Windows Phone 8.1 development, I have probably done something utterly incorrectly programming wise
The need: I want to download a text file from the web using HttpClient() and display it in the TextBlock1
From variety of tutorials I have found the following:
public async void DownloadDataAsync()
{
string data = "some link to Textfile.txt";
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(data);
HttpContent content = response.Content;
string result = await content.ReadAsStringAsync();
UpdateTextBlock1(result);
}
Then the other functions.
public void UpdateTextBlock1(string result)
{
TextBlock1.Text = result;
}
private void BtnDownloadData_Click(object sender, RoutedEventArgs e)
{
Task t = new Task(DownloadDataAsync);
t.Start();
}
The code starts well enough - on button pressed, I receive RPC_E_WRONG_THREAD.
Is it that I'm trying to call the method when all threads haven't finished? How can I code that efficently so the TextBlock1 is updated with txt data?
Thanks for understanding, baby steps here in programming, and I couldn't find a relevant answer over google. (Maybe I don't yet know how to ask?)
You need to update the textblock on the UI thread like so:
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
TextBlock1.Text = result;
});
There are many posts on this subject.
Why this piece of code crash silently my windows pone 8.1 emulator? If not the first time click it till it will do it (second or third time).
private async void MainPage_BackPressed(object sender, BackPressedEventArgs e)
{
var result = await WebViewControl.InvokeScriptAsync("eval", new string[] { document.location.href" });
e.Handled = true;
}
I'm working with my new app for Windows phone and using Nokia music api which is now Nokia mix radio api. There are many changes in it and MusicClientAsync is no longer functional.
I want to get list of top artist in user region. I'm trying to use following code but it is showing an error and I'm not able to find any documentation.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
MusicClient client = new MusicClient(MyAppId);
ListResponse{<MusicItem>} result = await client.GetTopArtistsAsync();
}
What you need to do, is to add the async keyworkd to your Button_Click method:
private async void Button_Click_1(object sender, RoutedEventArgs e)
{
MusicClient client = new MusicClient(MyAppId);
ListResponse{<MusicItem>} result = await client.GetTopArtistsAsync();
}
See how i add async word after private and before void this way your Button_Click_1 method can use the await keyword. THis way the call to GetTopArtistsAsync is going to work.