1

On newer version android I'm change startService to startForegroundService but service can't start.In manifest file is added ForegroundService permission.

LIntent := TJIntent.Create;
LIntent.setClassName(TAndroidHelper.Activity.getBaseContext, TAndroidHelper.StringToJString('myService'));  
TAndroidHelper.Activity.startForegroundService(LIntent);

On android 5 work fine:

LIntent := TJIntent.Create;
LIntent.setClassName(TAndroidHelper.Activity.getBaseContext, TAndroidHelper.StringToJString('com.embarcadero.services.myService'));
TAndroidHelper.Activity.startService(LIntent);
babayaro
  • 491
  • 3
  • 15
  • On later versions of Android, you need to create a notification that ends up being displayed to the user. There's an example of how to do this here: https://github.com/DelphiWorlds/Kastri/blob/1c20c99a005e03680d2d52b2fcc85effd990eca1/Demos/CrossPlatformLocation/Service/CPL.ServiceModule.pas#L274 – Dave Nottage Apr 06 '21 at 20:35

0 Answers0