pull/39/head
kunfei 5 years ago
parent 6446c13de6
commit 5cd2f669a1
  1. 8
      app/src/main/java/io/legado/app/service/ShareService.kt
  2. 25
      app/src/main/java/io/legado/app/service/WebService.kt
  3. 1
      app/src/main/res/values/strings.xml

@ -1,8 +0,0 @@
package io.legado.app.service
import io.legado.app.base.BaseService
class ShareService : BaseService() {
}

@ -2,8 +2,12 @@ package io.legado.app.service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.core.app.NotificationCompat
import io.legado.app.R
import io.legado.app.base.BaseService import io.legado.app.base.BaseService
import io.legado.app.constant.Action import io.legado.app.constant.Action
import io.legado.app.constant.AppConst
import io.legado.app.help.IntentHelp
import org.jetbrains.anko.startService import org.jetbrains.anko.startService
class WebService : BaseService() { class WebService : BaseService() {
@ -28,6 +32,7 @@ class WebService : BaseService() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
isRun = true isRun = true
updateNotification(getString(R.string.service_starting))
} }
override fun onDestroy() { override fun onDestroy() {
@ -41,4 +46,24 @@ class WebService : BaseService() {
} }
return super.onStartCommand(intent, flags, startId) 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<WebService>(this, Action.stop)
)
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
val notification = builder.build()
val notificationId = 1122
startForeground(notificationId, notification)
}
} }

@ -534,5 +534,6 @@
<string name="screen_find">筛选发现</string> <string name="screen_find">筛选发现</string>
<string name="dur_pos">当前位置:</string> <string name="dur_pos">当前位置:</string>
<string name="precision_search">精准搜索</string> <string name="precision_search">精准搜索</string>
<string name="service_starting">正在启动服务</string>
</resources> </resources>

Loading…
Cancel
Save