diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 13a812e8e..28c33ad9e 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -25,9 +25,7 @@ object IntentHelp { return PendingIntent.getService( context, 0, - Intent(context, T::class.java).apply { - this.action = action - }, + Intent(context, T::class.java).apply { this.action = action }, PendingIntent.FLAG_UPDATE_CURRENT ) } diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index 2e9f34ef8..ad0104675 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -297,24 +297,24 @@ abstract class BaseReadAloudService : BaseService(), builder.addAction( R.drawable.ic_play_24dp, getString(R.string.resume), - aloudServicePendingIntent(this, Action.resume) + aloudServicePendingIntent(Action.resume) ) } else { builder.addAction( R.drawable.ic_pause_24dp, getString(R.string.pause), - aloudServicePendingIntent(this, Action.pause) + aloudServicePendingIntent(Action.pause) ) } builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.stop), - aloudServicePendingIntent(this, Action.stop) + aloudServicePendingIntent(Action.stop) ) builder.addAction( R.drawable.ic_time_add_24dp, getString(R.string.set_timer), - aloudServicePendingIntent(this, Action.addTimer) + aloudServicePendingIntent(Action.addTimer) ) builder.setStyle( androidx.media.app.NotificationCompat.MediaStyle() @@ -326,6 +326,6 @@ abstract class BaseReadAloudService : BaseService(), startForeground(112201, notification) } - abstract fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent + abstract fun aloudServicePendingIntent(actionStr: String): PendingIntent? } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 7c40d15aa..2dde06378 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -1,10 +1,9 @@ package io.legado.app.service import android.app.PendingIntent -import android.content.Context -import android.content.Intent import android.media.MediaPlayer import io.legado.app.constant.Bus +import io.legado.app.help.IntentHelp import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefString import io.legado.app.utils.postEvent @@ -103,9 +102,7 @@ class HttpReadAloudService : BaseReadAloudService(), } } - override fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent { - val intent = Intent(context, HttpReadAloudService::class.java) - intent.action = actionStr - return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + override fun aloudServicePendingIntent(actionStr: String): PendingIntent? { + return IntentHelp.servicePendingIntent(this, actionStr) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt index 0909d16fa..b8cbdedfc 100644 --- a/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/TTSReadAloudService.kt @@ -1,8 +1,6 @@ package io.legado.app.service import android.app.PendingIntent -import android.content.Context -import android.content.Intent import android.os.Build import android.speech.tts.TextToSpeech import android.speech.tts.UtteranceProgressListener @@ -190,10 +188,8 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener } - override fun aloudServicePendingIntent(context: Context, actionStr: String): PendingIntent { - val intent = Intent(context, TTSReadAloudService::class.java) - intent.action = actionStr - return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + override fun aloudServicePendingIntent(actionStr: String): PendingIntent? { + return IntentHelp.servicePendingIntent(this, actionStr) } } \ No newline at end of file