Используя @notifee/react-native, я заявил
Код: Выделить всё
// for android foreground
if (Platform.OS === 'android') {
notifee.registerForegroundService(notification => {
return new Promise(() => {
// handle background event
notifee.onBackgroundEvent(async ({type, detail}) => {
const {pressAction} = detail;
if (type === EventType.ACTION_PRESS && pressAction?.id === 'mic') {
const result = togggleForegroundMic();
if (result) {
notifee.displayNotification({
id: notification.id,
body: notification.body,
android: {
...notification.android,
asForegroundService: true,
foregroundServiceTypes: [
AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_CAMERA,
AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MICROPHONE,
],
actions: [
{
title: result,
pressAction: {id: 'mic'},
},
// {
// title: 'Loud Speaker',
// pressAction: {id: 'speaker'},
// },
],
},
});
}
}
});
notifee.onForegroundEvent(({type, detail}) => {
if (
type === EventType.ACTION_PRESS &&
detail?.pressAction?.id === 'mic'
) {
const result = togggleForegroundMic();
if (result) {
notifee.displayNotification({
id: notification.id,
body: notification.body,
android: {
...notification.android,
asForegroundService: true,
foregroundServiceTypes: [
AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_CAMERA,
AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MICROPHONE,
],
actions: [
{
title: result,
pressAction: {id: 'mic'},
},
// {
// title: 'Loud Speaker',
// pressAction: {id: 'speaker'},
// },
],
},
});
}
}
if (
type === EventType.ACTION_PRESS &&
detail?.pressAction?.id === 'speakder'
) {
}
});
});
});
}
но это приводит к сбою моего приложения со следующей ошибкой
FATAL EXCEPTION: основной процесс: com.collabnowmobilecleint, PID: 30221 java.lang.RuntimeException: Unable чтобы запустить службу app.notifee.core.ForegroundService@cd7fb43 с намерением { act=app.notifee.core.ForegroundService.START cmp=com.collabnowmobilecleint/app.notifee.core.ForegroundService (есть дополнительные возможности) }: java.lang.IllegalArgumentException : foregroundServiceType 0x000000C0 не является подмножеством атрибута forgroundServiceType 0x00000800 в служебном элементе файла манифеста в android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4289) в android.app.ActivityThread.access$2000(ActivityThread.java:236) в android .app.ActivityThread$H.handleMessage(ActivityThread.java:2001) в android.os.Handler.dispatchMessage(Handler.java:107) в android.os.Looper.loop(Looper.java:264) в android.app. ActivityThread.main(ActivityThread.java:7684) в java.lang.reflect.Method.invoke(Native Method) в com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) в com.android. Internal.os.ZygoteInit.main(ZygoteInit.java:980) Причина: java.lang.IllegalArgumentException: foregroundServiceType 0x000000C0 не является подмножеством атрибута foregroundServiceType 0x00000800 в служебном элементе файла манифеста в android.os.Parcel.createException(Parcel. java:2075) в android.os.Parcel.readException(Parcel.java:2039) в android.os.Parcel.readException(Parcel.java:1987) в android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java) :6720) в android.app.Service.startForeground(Service.java:742) в app.notifee.core.ForegroundService.onStartCommand(SourceFile:21) в android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4271) в android .app.ActivityThread.access$2000(ActivityThread.java:236) в android.app.ActivityThread$H.handleMessage(ActivityThread.java:2001) в android.os.Handler.dispatchMessage(Handler.java:107) в android.os .Looper.loop(Looper.java:264) в android.app.ActivityThread.main(ActivityThread.java:7684) в java.lang.reflect.Method.invoke(Native Method) в com.android.internal.os.RuntimeInit $MethodAndArgsCaller.run(RuntimeInit.java:492) в com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) Вызвано: android.os.RemoteException: удаленная трассировка стека: в com.android.server. am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:1396) по адресу com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1034) по адресу com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:15727) в android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3056) в com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3153)
Я попробовал добавить следующие разрешения в файл манифеста моего приложения
Код: Выделить всё
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/790 ... set-of-for