diff --git a/samples/android/ntfy-service/Service.Module.Ntfy.pas b/samples/android/ntfy-service/Service.Module.Ntfy.pas index fcfcde0..7fce64a 100644 --- a/samples/android/ntfy-service/Service.Module.Ntfy.pas +++ b/samples/android/ntfy-service/Service.Module.Ntfy.pas @@ -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); diff --git a/samples/android/src/View.Main.pas b/samples/android/src/View.Main.pas index e1be468..06f8730 100644 --- a/samples/android/src/View.Main.pas +++ b/samples/android/src/View.Main.pas @@ -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);