Я получаю сообщение об ошибке в целевом SDK версии 34 для Android 14.
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() выполнил а затем не вызывать Service.startForeground(): ServiceRecord{5192954 u0 in.test.myApp/.KeepAliveService в android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2315)
в android.app. ActivityThread.throwRemoteServiceException(ActivityThread.java:2286)
в android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
в android.app.ActivityThread$H.handleMessage(ActivityThread. java:2611)
в android.os.Handler.dispatchMessage(Handler.java:106)
в android.os.Looper.loopOnce(Looper.java:230)
в android.os .Looper.loop(Looper.java:319)
в android.app.ActivityThread.main(ActivityThread.java:8913)
в java.lang.reflect.Method.invoke(собственный метод)
в com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
в com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Вызвано: android.app.StackTrace: последний вызов startServiceCommon() для этой службы был выполнен здесь
в android.app.ContextImpl.startServiceCommon(ContextImpl.java:2023)
в android.app.ContextImpl. startForegroundService(ContextImpl.java:1967)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:933)
в androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:701)
в in.test.myApp.KeepAliveService.onStartCommand(KeepAliveService.kt:53)
Вот мой код
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Util.createNotificationChannel()
val notificationIntent = Intent(this, LauncherActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
this,
0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val notification = NotificationCompat.Builder(this, AppConstant.channelID)
.setContentTitle(AppConstant.Title + " is running")
.setContentText("Tap here to open the app")
.setSmallIcon(R.drawable.notification_icon)
.setContentIntent(pendingIntent)
.build()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
startForeground(1, notification)
} else {
val foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
val startIntent = Intent(this, KeepAliveService::class.java)
startIntent.putExtra("notification", notification)
startIntent.putExtra("foregroundServiceType", foregroundServiceType)
ContextCompat.startForegroundService(this, startIntent) // Line number 53
}
return START_STICKY
}
Подробнее здесь: https://stackoverflow.com/questions/781 ... android-14
Проблема Service.startForeground() в Android 14 ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1710736534
Anonymous
Я получаю сообщение об ошибке в целевом SDK версии 34 для Android 14.[b]
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() выполнил а затем не вызывать Service.startForeground(): ServiceRecord{5192954 u0 in.test.myApp/.KeepAliveService[/b] в android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2315)
в android.app. ActivityThread.throwRemoteServiceException(ActivityThread.java:2286)
в android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
в android.app.ActivityThread$H.handleMessage(ActivityThread. java:2611)
в android.os.Handler.dispatchMessage(Handler.java:106)
в android.os.Looper.loopOnce(Looper.java:230)
в android.os .Looper.loop(Looper.java:319)
в android.app.ActivityThread.main(ActivityThread.java:8913)
в java.lang.reflect.Method.invoke(собственный метод)
в com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
в com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Вызвано: android.app.StackTrace: последний вызов startServiceCommon() для этой службы был выполнен здесь
в android.app.ContextImpl.startServiceCommon(ContextImpl.java:2023)
в android.app.ContextImpl. startForegroundService(ContextImpl.java:1967)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:847)
at androidx.core.content.ContextCompat$Api26Impl.startForegroundService(ContextCompat.java:933)
в androidx.core.content.ContextCompat.startForegroundService(ContextCompat.java:701)
в in.test.myApp.KeepAliveService.onStartCommand(KeepAliveService.kt:53)
Вот мой код
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Util.createNotificationChannel()
val notificationIntent = Intent(this, LauncherActivity::class.java)
val pendingIntent = PendingIntent.getActivity(
this,
0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
val notification = NotificationCompat.Builder(this, AppConstant.channelID)
.setContentTitle(AppConstant.Title + " is running")
.setContentText("Tap here to open the app")
.setSmallIcon(R.drawable.notification_icon)
.setContentIntent(pendingIntent)
.build()
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
startForeground(1, notification)
} else {
val foregroundServiceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE
val startIntent = Intent(this, KeepAliveService::class.java)
startIntent.putExtra("notification", notification)
startIntent.putExtra("foregroundServiceType", foregroundServiceType)
ContextCompat.startForegroundService(this, startIntent) // Line number 53
}
return START_STICKY
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78177923/service-startforeground-issue-in-android-14[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия