Developing Tizen .NET Applications with Alarm Manager
Developing Tizen .NET Applications with Alarm Manager
BY Annie Abraham2017年 08月 09日Tizen .NET Application, Tizen .NET
In the previous blog we learnt how to get started with Tizen .NET application, and how to develop a Drumpad application. In this blog we will learn about how to create a simple alarm application using Tizen AlarmManager APIs.
Prerequisites
The following tutorial assumes that you understand the structure of Tizen .NET application, and how to design UI using XAML file. If not, refer to the Drumpad application.
Steps
The following are the steps involved in creating the alarm application:
Alarm API is part of Tizen C # Native APIs, and hence cannot be directly called from the portable application. Using Dependency Service framework of Xamarin.Forms you can call the Tizen project from the portable project.
The following are the steps involved to create an alarm:
Create an interface with the required functionality. For this sample app you need to create an alarm with a given date, time, and notification text. Add the following code in IAlarmSetter.cs:
using System;
namespace TizenAlarm
{
public interface IAlarmSetter
{
void SetAlarm(DateTime time, string notifiText);
}
}
Add a class (TizenAlarmSetter.cs) in TizenAlarm.TizenMobile that implements IAlarmSetter interface. Add the following code in TizenAlarmSetter.cs:
using System;
using System.Threading.Tasks;
using Tizen.Applications;
using Tizen.Applications.Notifications;
using TizenAlarm.TizenMobile;
using Xamarin.Forms;
[assembly: Dependency(typeof(TizenAlarmSetter))]
namespace TizenAlarm.TizenMobile
{
class TizenAlarmSetter : IAlarmSetter
{
public void SetAlarm(DateTime time, string notifiText)
{
Notification noti = new Notification();
noti.Title = "Alarm";
noti.Content = notifiText;
noti.IsDisplay = true;
noti.AddStyle(new Notification.ActiveStyle());
AlarmManager.CreateAlarm(time, noti);
}
}
}
Register the class with Dependency Service module by adding: "[assembly: Dependency(typeof(TizenAlarmSetter))]". The Dependency Service module will call the corresponding implementation at runtime.
Create a notification with the content (reminder text) that is set by the user:
Once you have created the alarm, the final step is to call the TizenAlarmSetter SetAlarm () method from the TizenAlarm (portable) application. In AlarmPage.xaml.cs file, add click event handler for the button as follows:
Developing Tizen .NET Applications with Alarm Manager
In the previous blog we learnt how to get started with Tizen .NET application, and how to develop a Drumpad application. In this blog we will learn about how to create a simple alarm application using Tizen AlarmManager APIs.
Prerequisites
The following tutorial assumes that you understand the structure of Tizen .NET application, and how to design UI using XAML file. If not, refer to the Drumpad application.
Steps
The following are the steps involved in creating the alarm application:
Alarm Application Overview
This sample app is a simpler version of the Tizen Clock sample application. This app uses the AlarmManager APIs to create a simple alarm using Xamarin.Forms portable application.
Using this app, the user can set an alarm with a reminder text. When the alarm is triggered the user will get a notification with the reminder text.
Creating Project UI
In this sample app, XAML is used to design the UI in the TizenAlarm (portable) code. The required UI controls are:
The following are the steps to add the above listed UI controls over a StackLayout:
The following is the code in AlarmPage.xaml:
AlarmPage.xaml has a corresponding AlarmPage.xaml.cs file were the events can be handled when the user clicks the Add Alarm button.
Set AlarmPage as the Main Page of the application in TizenAlarm.cs by adding the following code in public App() function:
MainPage = new NavigationPage(new AlarmPage());
Build and run the application.
The following is the screenshot of the app:
Creating an Alarm
Alarm API is part of Tizen C # Native APIs, and hence cannot be directly called from the portable application. Using Dependency Service framework of Xamarin.Forms you can call the Tizen project from the portable project.
The following are the steps involved to create an alarm:
Binding Alarm Creation to Button Click Event
Once you have created the alarm, the final step is to call the TizenAlarmSetter SetAlarm () method from the TizenAlarm (portable) application. In AlarmPage.xaml.cs file, add click event handler for the button as follows:
And implement the event handler function as follows:
Adding the Privilege
This app requires the following privileges:
You can add this privilege to the tizen-manifest.xml file.
Running the App
Press CTRL+F5 to launch the application on the device/emulator, and
When the alarm is triggered a notification with the reminder text is displayed as follows:
For more details, refer to the attached source code.
BY Annie Abraham
2021年 09月 24日
Tizen Studio, Tizen .NET Application
BY Rishu Mehra
2020年 06月 30日
Tizen .NET, Tizen Studio, Tizen
BY Reni Mathew
2020年 06月 25日
Tizen .NET Application, Tizen .NET