notificação

Using Notification for Smartphones and Desktop with TotalCross

Notification is a message that will be displayed to the user outside of the application’s usual UI. When you execute a command telling the system to issue a notification, it will appear as an icon in the notification area, and to see the details, the user opens the notification space. The notification area and this space where the details are shown (also called the notification drawer) are areas controlled by the system and the user can see at any time.

notificação

 

Creation of a Notification

You specify actions and user interface information for a notification of the objectNotification.Builder. To create itselfnotification calls,Notification.Builder.build() which returns anNotification object containing its specifications. To issue the notification, pass the objectNotification to the system by calling.NotificationManager.getInstance().Notify();

Content Needed to Create a Notification

The object on smartphones should contain the following:

  • A title, defined by title();
  • Detail text, defined by text();

A Simple Example

Let’s create a class called Notification inheriting from.MainWindow Next, let’s create in twoinitUI() text fields, one for the title and one for text in detail. Let’s also create a,button which will trigger the notification.


Edit title = new Edit("Title");
title.caption = "Title";
add(title, CENTER, AFTER+50, SCREENSIZE+50, PREFERRED);

Edit text = new Edit("Text");
text.caption = "Text";
add(text, CENTER, AFTER+50, SCREENSIZE+50, PREFERRED);

btnHello = new Button("Notify!");
btnHello.addPressListener(
(e) -> {
Notification.Builder builder = new       Notification.Builder();
Notification notification = builder
.title(title.getText())
.text(text.getText())
.build();
NotificationManager.getInstance().notify(notification);
});
add(btnHello, CENTER, AFTER+150, PARENTSIZE+38, PARENTSIZE+8);

To better understand, just watch the video and to see the complete example just go to gitHub!


What’s up? Did you like to generate notifications for all platforms easily and with a single code using TotalCross? If this is your first time with TotalCross, it’s good to start with HelloWorld, huh!


Esse artigo foi útil?
[Total: 0 Average: 0]
Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Email this to someone

Comments

comments