Show/Hide Toolbars

Android Applications

Navigation: Android Specifics

Mobile Notifications

Scroll Prev Top Next More

Tutorial

 

Add Notification Center to both sender and receiver apps.

Examples https://github.com/Embarcadero/RADStudio10.4Demos/tree/master/Object%20Pascal/Mobile%20Snippets/AndroidIntents

 

Simple

 Notification := NotificationCenter.CreateNotification;

 try

   Notification.Name := 'MyNotification';

   Notification.AlertBody := 'Delphi for Mobile is here!';

   Notification.FireDate := Now;

 

   { Send notification in Notification Center }

   NotificationCenter.PresentNotification(Notification);

   { also this method is equivalent if platform supports scheduling }

   //NotificationCenter.ScheduleNotification(Notification);

 finally

   Notification.DisposeOf;

 end;

 

 

Or

 

Add Notification Center to a Service module and show an ongoing notification required in the latest Android for "Services" running in the foreground.

Example https://github.com/Embarcadero/RADStudio10.4Demos/tree/master/Object%20Pascal/Multi-Device%20Samples/Device%20Sensors%20and%20Services/Foreground%20Location%20Tracking

 

 

 

Use TJNotificationCompat_Builder to Build the Notification.

Use https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder to Build the notification.

 

init     Changes between Berlin and Sydney

 

Init Sydney

 Builder := TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context, StringToJString(NotificationChannelId));

Init Berlin

 Builder := TJNotificationCompat_Builder.JavaClass.init(TAndroidHelper.Context);

 

Builder Functions

Use setContentIntent to include the intent used to start the native activity after the user taps on the ongoing notification.

Use AddAction  to include the intent used to provide activate an additional action by pressing on text in the notification.

 

SetPriority(TJNotification.JavaClass.PRIORITY_HIGH);

setOngoing(True);

setSmallIcon                  GetIconId Integer

setContentTitle               StrToJCharSequence(NotificationTitle)  {Limited Chars}

setContentText               StrToJCharSequence(NotificationContent)  (Limit about 36 Chars)

setTicker                       Sets the "ticker" text which is sent to accessibility services.

setWhen    Time of notification          eg.   TJDate.Create.getTime;