live tile is not updating in Windows Phone - c#

i am developing a windows phone app where application has an option to pin the application to home screen. And i am using ShellTileSchedule class to do schedule the update periodically. Some reason my app is not pushing any update to tile. My app data is completely local, no data is coming from outside.
In my tile update, i am not updating any image on the lile, but only changing the data to display.
foreach (ShellTile tile in ShellTile.ActiveTiles)
{
IconicTileData tileData = GetTileData();
tileSchedule = new ShellTileSchedule(tile, tileData);
tileSchedule.Interval = UpdateInterval.EveryHour;
tileSchedule.Recurrence = UpdateRecurrence.Interval;
tileSchedule.Count=GetUserData();
tileSchedule.StartTime = DateTime.Now;
tileSchedule.Start();
tile.Update(tileData);
}
Any help in this regard? Or do i need to background agent to update the tile?

ShellTileSchedule can only pull images off the web, not from the phone itself. This is one of the limitations of ShellTileSchedule. If you want to set background images to resources on the phone, look at using push notifications instead.
Source: http://www.silverlightshow.net/news/WP7-Using-ShellTileSchedule-to-update-your-app-s-Live-Tile-background.aspx

Shouldn't you be setting a ShellTileSchedule.RemoteImageUri somewhere? I mean, that's kinda what ShellTileSchedule is there for, to update your tile image from a remote Uri on a regular interval... See sample of how to use this class for secondary tiles here.

You have to fill the properties of IconicTileData. In your sample you just create empty data structure and use it for the schedule, that won't work. I use it like this:
IconicTileData newTileData = new IconicTileData
{
Title = SharedResources.AppName,
Count = BatteryHelper.BateryLevel,
SmallIconImage = new Uri(#"/Assets/IconicSmall.png", UriKind.Relative),
IconImage = new Uri(#"/Assets/IconicMedium.png", UriKind.Relative),
};

Related

Pushpin events C#?

https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/pushpins/pushpin-events-example
If I'm trying to make an app on C# using Bing Maps API, is it possible to have pushpin events like in the link above? Some sample code I found lets me put a pushpin like thisenter image description here
This is the section of code that created 4 pushpins(only 2 visible in the picture).
var r = new ImageryRequest()
{
CenterPoint = new Coordinate(coord1, coord2),
ZoomLevel = 5,
ImagerySet = ImageryType.RoadOnDemand,
Pushpins = new List<ImageryPushpin>(){
new ImageryPushpin(){
Location = new Coordinate(45, -120.01),
Label = "hi"
},
new ImageryPushpin(){
Location = new Coordinate(0, 1),
IconStyle = 3
},
new ImageryPushpin(){
Location = new Coordinate(coord1, coord2),
IconStyle = 20
},
new ImageryPushpin(){
Location = new Coordinate(33, -75),
IconStyle = 24
}
},
BingMapsKey = BingMapsKey,
};
It looks like you are using the BingMapsRestToolkit that provides a c# API for accessing the Bing Maps REST services. In particular, you are calling the static imagery service which returns an image, not an interactive map. If you wanted to write some code so that someone could click on a pushpin in the image and you would know it, there would be a decent amount of math involved. It can be done, but you might be better to first consider using an interactive map SDK in your app instead as that would provide a lot more capabilities that would allow the user to interact with the map. Bing Maps has two interactive map SDKs that you can develop with using C#.
There is the Windows UWP map SDK that can be used in Windows apps, and in WPF apps via a XAML island. Here are some useful resources:
https://learn.microsoft.com/en-us/windows/uwp/maps-and-location/
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-standard-control-with-xaml-islands
There is also an older WPF SDK that has fewer capabilities than the UWP SDK. It is generally recommended to use the UWP map control, but if you want to use this, here are the details: https://learn.microsoft.com/en-us/previous-versions/bing/wpf-control/hh750210(v%3dmsdn.10)

How can I fix overexposed high resolution photos using Media Foundation?

I'm using Media Foundation in my WPF application to implement functionality that is similar to the Windows Camera App: show a live webcam feed and take a high resolution image when pressing a button. While the Windows Camera App always takes a correctly exposed snapshot, the snapshot taken by Media Foundation is often overexposed.
The application is only used by devices that have built-in high resolutions for Photos (eg Surface Go 2, Surface 7 Pro, ...). A specific image stream is used to take the snapshot instead of reading one frame of the video stream.
I have already tried changing the IAMCameraControl and IAMVideoProcAmp properties like Exposure or Brightness before taking a snapshot but the photo was always overexposed.
Are there any additional settings or approaches for fixing overexposure when taking a high resolution snapshot (eg. the same way the Windows Camera App works)?
Overexposed snapshot
High resolutions for photos
Code to take the snapshot
IMFCaptureEngineClassFactory captureEngineClassFactory = null;
IMFCaptureEngine captureEngine = null;
IMFCapturePhotoSink capturePhotoSink = null;
IMFMediaType photoMediaType = null;
try
{
// Create a CaptureEngineClassFactory
captureEngineClassFactory = mff.GetCaptureEngineClassFactory();
// Create a CaptureEngine
captureEngine = mff.GetCaptureEngine(captureEngineClassFactory);
// Initialize the CaptureEngine
MFCaptureEngineOnEventCallback captureEngineOnEventCallback = MFCaptureEngineOnEventCallback.GetInstance();
mff.Initialize(captureEngine, captureEngineOnEventCallback, mediaSource);
captureEngineOnEventCallback.WaitUntilInitialized();
// Create a Photo Sink
capturePhotoSink = mff.CreateCapturePhotoSink(captureEngine);
// Create a Photo Media Type
photoMediaType = CreatePhotoMediaType(mediaType);
// Remove all streams
mff.RemoveAllStreams(capturePhotoSink);
// Add Stream
int sinkStreamIndex = mff.AddStream(capturePhotoSink, streamIndex, photoMediaType);
// Set output filename
mff.SetSampleCallback(capturePhotoSink, this);
// Take photo
mff.TakePhoto(captureEngine);
captureEngineOnEventCallback.WaitUntilDone();
// imageSource should be filled in after executing TakePhoto
return image;
}
finally
{
TryRelease(captureEngineClassFactory);
TryRelease(captureEngine);
TryRelease(capturePhotoSink);
TryRelease(photoMediaType);
}

Xamarin.Forms Windows App load XML data into ListView

I am writing an application in Xamarin.Forms for Android, iOS, and Windows Store. I want to populate a ListView with about 10,000 elements from an XML file. The problem is when I run the code for Windows Phone or Windows Store, the application lags for about a minute before coming back alive and populating the ListView. It populates instantly for Android and iOS. However for Windows, it lags. Could somebody help me fix this problem? Here is my code which does the reading of XML and populating the ListView:
public async void LoadCharacters()
{
Assembly assembly = typeof(CharacterPage).GetTypeInfo().Assembly;
string file = assembly.GetManifestResourceNames().First(x => x.Contains("Characters.xml"));
Stream stream = assembly.GetManifestResourceStream(file);
data = new ObservableCollection<Character>();
await Task.Factory.StartNew(delegate {
XDocument doc = XDocument.Load(stream);
IEnumerable<Character> characters = from query in doc.Descendants("c")
select new Character
{
Simplified = query.Attribute("s").Value,
Traditional = query.Attribute("t").Value,
Pinyin = query.Attribute("p").Value,
English = query.Attribute("e").Value,
URL = query.Attribute("u").Value
};
data = characters.ToObservableCollection();
});
characterList.ItemsSource = data;
}
This code works, and runs smooth in iOS and Android. However in Windows, it hangs for about 1 minutes. Please help.
Thank you
The answer is to set the height of the listview item. Then it loads instantly.

Call Navigation/Maps/Drive with an Address in WP8.1 Application

I was wondering if it's possible to call the default navigation application within my Windows Phone 8.1 application. I have an address and I would like for the user to press a button and be able to navigate to that address through the default navigation app. If this is possible, how do I do it?
Thanks for your time,
Johan
You can launch turn-by-turn directions apps using the ms-drive-to and ms-walk-to schemes (depending on the type of directions you want) but you first need to get a geocoordinate for the address that you have. Since you're targeting Windows Phone 8.1, you can use the MapLocationFinder class in the Windows.Services.Maps namespace.
string locationName = "Empire State Building";
string address = "350 5th Avenue, New York City, New York 10018";
var locFinderResult = await MapLocationFinder.FindLocationsAsync(
address, new Geopoint(new BasicGeoposition()));
// add error checking here
var geoPos = locFinderResult.Locations[0].Point.Position;
var driveToUri = new Uri(String.Format(
"ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
geoPos.Latitude,
geoPos.Longitude,
locationName));
Launcher.LaunchUriAsync(driveToUri);
the official solution is:
Uri uri = new Uri("ms-drive-to:?destination.latitude=" + latitude.ToString(CultureInfo.InvariantCulture) +
"&destination.longitude=" + longitude.ToString(CultureInfo.InvariantCulture))
var success = await Windows.System.Launcher.LaunchUriAsync(uri);
if (success)
{
// Uri launched.
}
else
{
MessageBox.Show("error");
}
But, there is a problem with this solution.
If you use the nokia programs (HERE), it works fine.
if you want to use waze, you have to add origin.latitude and origin.longitude.
in the MSDN page, They said that it is not necessary, but in fact, you have to write it.
I am already not enable to load moovit but if someone has an issue, it'll help me a lot.

How to end Periodic Updates to a Windows 8 Live Tile

I've seen lots of examples of how to begin Periodic Updates to a live tile in Windows 8, e.g:
PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;
System.Uri url = new System.Uri(polledUrl);
TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(url, recurrence);
However, how do you undo this? I've added an app setting to disable the live tile updates but I can't find code to remove the polling.
I discovered the answer by browsing through the Intellisense options.
To revert a tile to its default state, i.e. not live, use:
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
Hope this helps someone - it wasn't easy to find in any of the Windows Dev Centre Quickstarts.
PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.Hour;
System.Uri url = new System.Uri(polledUrl);
var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
tileUpdater.StartPeriodicUpdate(url, recurrence);
// ...
tileUpdater.StopPeriodicUpdate();

Categories