Я хочу создать службу переднего плана, которая будет работать даже после закрытия приложения в qt. Я прочитал это https://doc.qt.io/qt-5/android-services.html Простые службы работают успешно, но когда я пытаюсь запустить службу переднего плана в своей функции
public static void startQtAndroidService(Context context) {
/*context.startService(new Intent(context, smsForwardService.class));
Log.i("smsForwardService", "Service started");
*/
Intent notificationIntent = new Intent(context, smsForwardService.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notification =
new Notification.Builder(context, "i don't know what is it, so i just put this text here")
.setContentTitle("SMSForwardService")
.setContentText("Service working")
.setContentIntent(pendingIntent)
.build();
// Notification ID cannot be 0.
startForeground(666, notification);
}
компилятор пишет мне это
:-1: ERROR: D:\projects\FKey\build-FKey-Android_Qt_5_15_1_Clang_Multi_Abi_05487b-Debug\android-build\src\smsForwardService.java:54: error: non-static method startForeground(int,Notification) cannot be referenced from a static context
startForeground(666, notification);
^
Note: Some input files use or override a deprecated API.
Что я делаю не так? Почему startService работает, а startForeground не работает? практически ничего не изменилось, я просто создаю уведомление и запускаю сервис с другой функцией.