Skip to content

Commit

Permalink
🚧 Android example updates
Browse files Browse the repository at this point in the history
  • Loading branch information
p-samuel committed Aug 27, 2024
1 parent 91e95a8 commit 5ed03ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion samples/android/ntfy-service/Service.Module.Ntfy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,19 @@ function TNtfyAndroidServiceModule.AndroidServiceStartCommand(

procedure TNtfyAndroidServiceModule.DumbProcedure;
begin
// This works

TThread.CreateAnonymousThread(
procedure
begin

// This doesn't work, perhaps because of the mechanism on how Android deal with threads...
// Ntfy.Subscribe('ntfy-android-test-delphi',
// procedure (AEvent: INotifyEvent)
// begin
// PushNotification(AEvent)
// end);

// This works, it displays the notification....
while True do
begin
TThread.Sleep(5000);
Expand Down
21 changes: 14 additions & 7 deletions samples/android/src/View.Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,20 @@ procedure TForm1.Button1Click(Sender: TObject);
LTask := TTask.Create(
procedure
begin
//LJIntent := TJIntent.Create;
//LJIntent.setClassName(
// TAndroidHelper.Context,
// StringToJString('com.embarcadero.services.NtfyAndroidService'));
// TAndroidHelper.Context.startForegroundService(LJIntent);
FNtfyService := TLocalServiceConnection.Create;
FNtfyService.StartService('NtfyAndroidService');


// You can use both options, broadcasting an intent...
LJIntent := TJIntent.Create;
LJIntent.setClassName(
TAndroidHelper.Context,
StringToJString('com.embarcadero.services.NtfyAndroidService'));
TAndroidHelper.Context.startForegroundService(LJIntent);


// Or starting the service...
//FNtfyService := TLocalServiceConnection.Create;
//FNtfyService.StartService('NtfyAndroidService');

end);


Expand Down

0 comments on commit 5ed03ef

Please sign in to comment.