Sorry I fix.
function TDM.AndroidServiceStartCommand(const Sender: TObject;
const Intent: JIntent; Flags, StartId: Integer): Integer;
var
//Android 8.1
ServiceChannel: JNotificationChannel;
NotificationManager: JNotificationManager;
Obj: JObject;
NewIntent: JIntent;
ncb: JNotificationCompat_Builder;
ntf: JNotification;
PendingIntent: JPendingIntent;
//Android 7.1
service : JService;
serviceObjectId : Pointer;
ntf2 : JNotification;
intent2 : JIntent;
PendingIntent2 : JPendingIntent;
begin
Result := TJService.JavaClass.START_NOT_STICKY;
// can't ref .O on earlier phones, must hardcode
if TJBuild_VERSION.JavaClass.SDK_INT > 26 then // JBuild_VERSION_CODES.JavaClass.O
begin
//Android 8.1
//new ways for SDK > 26 (won't be called when API < 26 anyways)
ServiceChannel := TJNotificationChannel.JavaClass.init(
StringtoJString('com.radio.one'), //CHANNEL_ID
StrToJCharSequence('Public radio Channel'),
TJNotificationManager.JavaClass.IMPORTANCE_DEFAULT
);
Obj := TAndroidHelper.Context.getSystemService(
TJContext.JavaClass.NOTIFICATION_SERVICE);
NotificationManager := TJNotificationManager.Wrap(Obj);
NotificationManager.createNotificationChannel(ServiceChannel);
NewIntent:= TAndroidHelper.Context.getPackageManager().getLaunchIntentForPackage(
TAndroidHelper.Context.getPackageName());
NewIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);
NewIntent.addCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
NewIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
PendingIntent := TJPendingIntent.JavaClass.getActivity(
TAndroidHelper.Context, 0, NewIntent,
TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK
);
ncb := TJNotificationCompat_Builder.JavaClass.init(
TAndroidHelper.Context,
StringToJString('com.radio.one')
);
ncb.setContentTitle(StrToJCharSequence('PublicRadio Service'));
// ncb.setTicker(StrToJCharSequence('MyCommsService')); // can't remember why this is commented out to be honest
ncb.setSmallIcon(JavaService.getApplicationInfo.icon);
ncb.setContentIntent(PendingIntent);
ncb.setOngoing(True);
ntf := ncb.build;
JavaService.startForeground(StartId, ntf);
end
else
begin
//Android 7.1
serviceObjectId := (JavaService as ILocalObject).GetObjectID;
service := TJService.Wrap(serviceObjectId);
/////ntf2 := TJNotification.Create;
////ntf2.icon := service.getApplicationInfo.icon;
NewIntent:= TAndroidHelper.Context.getPackageManager().getLaunchIntentForPackage(
TAndroidHelper.Context.getPackageName());
NewIntent.setAction(TJIntent.JavaClass.ACTION_MAIN);
NewIntent.addCategory(TJIntent.JavaClass.CATEGORY_LAUNCHER);
NewIntent.addFlags(TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK);
PendingIntent2 := TJPendingIntent.JavaClass.getActivity(
TAndroidHelper.Context, 0, NewIntent,
TJIntent.JavaClass.FLAG_ACTIVITY_NEW_TASK
);
ncb := TJNotificationCompat_Builder.JavaClass.init(
TAndroidHelper.Context,
StringToJString('com.radio.one')
);
//intent2 := TJIntent.Create;
//PendingIntent2 := TJPendingIntent.JavaClass.getActivity(service.getApplicationContext, 0, intent2, 0);
ncb.setContentTitle(StrToJCharSequence('PublicRadio'));
// ncb.setTicker(StrToJCharSequence('MyCommsService'));
ncb.setSmallIcon(JavaService.getApplicationInfo.icon);
ncb.setContentIntent(PendingIntent2);
ncb.setOngoing(True);
ntf2 := ncb.build;
ntf2.setLatestEventInfo(service.getApplicationContext, StrToJCharSequence('PublicRadio'), StrToJCharSequence('PublicRadio Service'), PendingIntent2);
service.startForeground(StartId, ntf2);
end;
end;