How to show a progress bar notification in xamarin forms - c#

I am using xamarin forms and i came across this plugin https://github.com/thudugala/Plugin.LocalNotification in order to show notifications to user. But how can a progress bar be shown on notification area?
I cant find an example of how this is done.
This is the code i use for sending notification
CrossLocalNotifications.Current.Show("title", "body");
Is there a cross platform solution as the above example? Or a correct implementation using Dependency Services?

What you're trying to achieve is not possible with the local notification plugin. However, it should be rather trivial to extend the library to add an additional argument for the progress data shown on the progress bar.
Basically, you just need to pass two additional values from the Notification Builder by calling the SetProgress(int max, int progress, bool intermediate) method. This is best explained in Google's Android documentation here.
The method were you should add the call to SetProgress() is ShowNow() in the Android specific class /Platform/Droid/NotificationServiceImpl.cs. Of course you also need to make changes elsewhere so that you can provide the max and progress values from the cross-platform code.
If the above solution seems too complex and you're not using the plugin extensively, perhaps you can just construct the notifications yourself in the Android project and execute that code using the dependency service.
Edit: I removed the Google Books link which doesn't seem to work for everyone. Instead, here is an article from Microsoft Docs, detailing how the local notifications can be created. The only additional thing that is missing from the guies is the SetProgress method which is required to show the progress bar.
Also, notice that you need to submit the notification again and again to show progress in the progress bar. Check the third reply (from Cheesebaron) on this thread in the Xamarin Forums for a short explanation and bits of code on how it works.

Related

How to display UI for App Center Crashes in UWP

We have a UWP app in which we send crash reports using the App Center Crashes api.
In the docs there is a section about displaying UI to the user that a crash report is being submitted, has sent or has failed.
We have been unable to call our own custom UI.
Is there an example on how to call custom UI?
Crashes.SendingErrorReport += async (sender, e) =>
{
// Your code, e.g. to present a custom UI.
};
We don't have any OnProgress-type of callbacks, so the only option is using 3 events we have:
SendingErrorReport, SentErrorReport and FailedToSendErrorReport.
There is no snippets of usage in UWP demo\puppet apps I can show, but you can have a look at WPF code for example, callback signatures are the same.
Basically what you described in original post is correct. I think that something like MessageDialog (documentation is here) is what you are looking for.
Hope that helps.
I can confirm - I was just trying the same issue on UWP - it does NOT work. Will see how I can submit an issue to Appcenter (apparently i don't have enough reputation to add it as a comment).

How to resume where left off after sleep

I would like to make my Xamarin.Forms cross-platform app have the ability to resume after it sleeps.
I have been googling for a while but haven't found any solutions.
I tried reading this Xamarin tutorial but it doesn't seem to have anything for what I am trying to accomplish.
I tried looking for something like base.OnResume() but there is no base variable or any methods.
Xamarin Forms has an OnSleep and an OnResume method in the Application class
These can be used to save and restore variables when the app is backgrounded and resumed.
It is up to you to save the details you need such as page to load and state to restore. Look at the persist data section.
Here is a blog post about doing this.
You can find this methods in your app.xml file. Handle your code inside that file whatever you want to do onresume

background task in windows phone 8.1

I am using a 3rd party rest api to query data and display it in my app. I have to perform a task like at night 12 approx. it will perform a background task to query data from rest api and update live tile and generate notification. I would like to use only C# only for this task. I don't know what will be best approach to do this task. But I using below code to perform background task to do this which is not working. Not sure why?
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = taskName;
SystemTrigger trigger = new SystemTrigger(SystemTriggerType.InternetAvailable, false);
taskBuilder.SetTrigger(trigger);
taskBuilder.AddCondition(new SystemCondition(SystemConditionType.InternetAvailable));
taskBuilder.TaskEntryPoint = typeof(BackgroundTask.BackgroundTask).FullName;
taskBuilder.Register();
and from background task I am querying data and generating toast notification.
Any help why this code is not working or when this task will fire. Is there any better approach to do above task?
Thanks
Regarding the code you have not working...
For Windows Phone 8.1 unlike Windows 8\8.1, you are required to call BackgroundExecutionManager.RequestAccessAsync() (search MSDN\internet) for ANY background task before registering task(s) whereas in Windows this is only required for some tasks. Make sure your code calls this and validate the returned value before registering your background task(s).
Regarding knowing if your task "worked"...
It's a good idea to have the background task implementation run (IBackgroundTask::Run()) independent of the trigger\conditions you've set to ensure it performs without issue by debugging it. See instructions in the following link: http://msdn.microsoft.com/en-US/library/windows/apps/xaml/jj542416.aspx.
Regarding your use of SystemConditionType.InternetAvailable...
I'm not 100% about this but I'm pretty certain this will be redundant given you already have a SystemTriggerType.InternetAvailable. I don't know of a situation where the trigger would fire but the condition wouldn't be true.
Regarding the requirement you've mentioned...
If I understand your requirement correctly you have different options here:
If your app is a Windows Phone XAML app that need to run based on time, I would recommend either TimeTrigger or MaintenanceTrigger triggers (as opposed to the SystemTrigger). These are both Background Tasks. For general info on Background Tasks and links to the TimeTrigger and MaintenanceTrigger documentation see this MSDN link: http://msdn.microsoft.com/en-US/library/windows/apps/xaml/hh977056.aspx.
If your app is a Windows Phone Silverlight 8.0 app you can use Background Agents, specifically either PeriodicTask or ResourceIntensiveTask. See the links posted by others or search the MSDN\internet for more info.
If your app is a Windows Phone Silverlight 8.1 app you can use the option in either 1 or 2 above.
I think you should try using PeriodicTask. Also consider the constraints mentioned in the link.
create one class with output Type :Windows Runtime Component
and put your Class that inheritance from IBackroundTask so this work
if you use from emulator for launching app, i think your app for register task not active in emulator.

How can I update my tiles in the background in Windows 8?

How can I update my tiles in the background while my app is not running in the foreground? I tried looking into push notifications, but I don't think that'll get me anywhere.
Where to begin? I know how to create tiles already.
An app cannot update it's tile without running at least once. Because apps do not run immediately on installation, it isn't possible for a tile to be "live" until it is launched. After app installation, the user needs to launch the app for it to set up and begin receiving updates in any form (whether they are push notifications, periodic updates, scheduled notifications, or local notifications raised with or without a background task). The default tile will be shown from the point the user installs the app until the time the app sets up tile updates.
MSDN has a good article on choosing the right notification delivery mechanism, which also links to related code samples:
http://msdn.microsoft.com/en-us/library/windows/apps/hh779721.aspx
As far as I know, you have to use a background task. If the user hasn't run the app once, you can't show any interactive tile data.
You have to use a TileNotification from the Windows.UI.Notifications namespace. The documentation for the namespace is here.
There's also an example Stocks app that uses notifications here (search for 'Tiles and notifications')
Further, there's an 'App tiles and badges' sample that shows both text and image updates to a live tile.
Adding Live tiles to the desktop using c# code:
List<Uri> StoryUrls = new List<Uri>();
StoryUrls .Add(new Uri("tiles.xml"));
TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdateBatch(StoryUrls, PeriodicUpdateRecurrence.HalfHour);
The xml should be in the following format:
tiles.xml should follow microsoft format show in step 5 Here
Hope this helps

Getting in message loop of external application

I need to retrieve values from an external application but it does not provide any API to do so. The values are ever-changing and not fixed.
Is there a way to retrieve the values from the application?
Maybe getting into the message loop for that particular application and filtering for certain window messages which contains the value. Or perhaps, using Microsoft Automation Toolkit to search for the relevant controls and getting the values of it.
Thanks for taking your time to read this.
P.S. I was looking into something like SetWindowsHookEx or anything similar.
Does it help to use RegisterWindowMessage if I were to know the string which the application used to register?
You'll need to setup a global Windows Hook and you need to write a C++ DLL for receiving the callback. I'd suggest looking at this MSDN Magazine article. It describes a tool called ManagedSpy but even if you want to "spy" on an unmanaged app the hook code should be the same.

Categories

Resources