I am building a notification service and I am currently facing an issue when trying to display any kind of image in it.
I am using Microsoft.Toolkit.Uwp.Notifications and below is the code I am using to show build and show the notification.
static class NotificationTemplate
{
public static ToastContentBuilder HelpDesk(string main_payload, string additional_data, string type)
{
return new ToastContentBuilder()
.AddArgument("type", "helpdesk")
.AddArgument("select", main_payload)
.AddText("Incoming ticket", AdaptiveTextStyle.Title)
.AddText(type, AdaptiveTextStyle.Header)
.AddAttributionText(additional_data)
.AddAppLogoOverride(new Uri("https://cdn4.iconfinder.com/data/icons/the-weather-is-nice-today/64/weather_11-64.png"))
.AddButton(new ToastButton()
.AddArgument("take", main_payload)
.SetContent("TAKE"))
.AddButton(new ToastButton()
.AddArgument("close", main_payload)
.SetContent("CLOSE"));
}
}
The image I use in the Uri is valid(a test link, not the actual thing) and is shown when opening the link in a browser.
Below is a screenshot of the shown notification:

I am running Windows 10 build 19045.3324
It's explicitly mentioned in the docs:
ⓘ Important
Http images are supported only in packaged apps that have the internet capability in their manifest. Unpackaged apps don't support http images; you must download the image to your local app data, and reference it locally.
As you have mentioned you are not using a packaged app, then you must download the image yourself, either at design-time or run-time.
You can download it and add it to the solution and copy it to the output directory, or you can download and use it at run-time. For example:
static WebClient client = new WebClient();
private async void button1_Click(object sender, EventArgs e)
{
var fileName = Path.Combine(Application.StartupPath, "Logo.jpg");
if(!File.Exists(fileName))
{
var address = "https://picsum.photos/360/202?image=883";
await client.DownloadFileTaskAsync(new Uri(address), fileName);
}
ToastContentBuilder builder = new ToastContentBuilder()
.AddText("Lorem Ipsum!")
.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
.AddAppLogoOverride(new Uri(fileName));
builder.Show();
}
Note: Not the concern of this question/answer, but to download the file, it's recommended to use HttpClient. Look at this example.
As mentioned in the documents, for packaged app, if internet access is enabled, you don't need to download the image and you can use the image url. To learn more, take a look at following resources:
And yes, both solutions (without download For packaged apps, and with download for non-packaged apps) work on debug mode as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With