From 5cd2f669a1e3174ca1babccfa2ff7b3cd7868616 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 23 Oct 2019 17:30:07 +0800 Subject: [PATCH] up --- .../io/legado/app/service/ShareService.kt | 8 ------ .../java/io/legado/app/service/WebService.kt | 25 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 26 insertions(+), 8 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/service/ShareService.kt diff --git a/app/src/main/java/io/legado/app/service/ShareService.kt b/app/src/main/java/io/legado/app/service/ShareService.kt deleted file mode 100644 index 49624ecc3..000000000 --- a/app/src/main/java/io/legado/app/service/ShareService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package io.legado.app.service - -import io.legado.app.base.BaseService - -class ShareService : BaseService() { - - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 3dcefd09d..eec294aa1 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -2,8 +2,12 @@ package io.legado.app.service import android.content.Context import android.content.Intent +import androidx.core.app.NotificationCompat +import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.Action +import io.legado.app.constant.AppConst +import io.legado.app.help.IntentHelp import org.jetbrains.anko.startService class WebService : BaseService() { @@ -28,6 +32,7 @@ class WebService : BaseService() { override fun onCreate() { super.onCreate() isRun = true + updateNotification(getString(R.string.service_starting)) } override fun onDestroy() { @@ -41,4 +46,24 @@ class WebService : BaseService() { } return super.onStartCommand(intent, flags, startId) } + + /** + * 更新通知 + */ + private fun updateNotification(content: String) { + val builder = NotificationCompat.Builder(this, AppConst.channelIdWeb) + .setSmallIcon(R.drawable.ic_web_service_noti) + .setOngoing(true) + .setContentTitle(getString(R.string.web_service)) + .setContentText(content) + builder.addAction( + R.drawable.ic_stop_black_24dp, + getString(R.string.cancel), + IntentHelp.servicePendingIntent(this, Action.stop) + ) + builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + val notification = builder.build() + val notificationId = 1122 + startForeground(notificationId, notification) + } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47d72c6a5..b2f63d0ba 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -534,5 +534,6 @@ 筛选发现 当前位置: 精准搜索 + 正在启动服务