pull/32/head
kunfei 5 years ago
parent debf517d1d
commit 43530e2246
  1. 2
      app/src/main/AndroidManifest.xml
  2. 4
      app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt
  3. 6
      app/src/main/java/io/legado/app/service/ReadAloudService.kt

@ -64,7 +64,7 @@
<service android:name=".service.UpdateService" />
<service android:name=".service.WebService" />
<receiver android:name=".receiver.MediaButtonIntentReceiver">
<receiver android:name=".receiver.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>

@ -11,10 +11,10 @@ import android.view.KeyEvent
* 监听耳机键
*/
class MediaButtonIntentReceiver : BroadcastReceiver() {
class MediaButtonReceiver : BroadcastReceiver() {
companion object {
val TAG = MediaButtonIntentReceiver::class.java.simpleName
val TAG = MediaButtonReceiver::class.java.simpleName
fun handleIntent(context: Context, intent: Intent): Boolean {
val intentAction = intent.action

@ -18,7 +18,7 @@ import io.legado.app.constant.AppConst
import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.help.PendingIntentHelp
import io.legado.app.receiver.MediaButtonIntentReceiver
import io.legado.app.receiver.MediaButtonReceiver
import io.legado.app.utils.postEvent
import io.legado.app.utils.toast
import kotlinx.coroutines.launch
@ -140,7 +140,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
* 初始化MediaSession
*/
private fun initMediaSession() {
val mComponent = ComponentName(packageName, MediaButtonIntentReceiver::class.java.name)
val mComponent = ComponentName(packageName, MediaButtonReceiver::class.java.name)
val mediaButtonIntent = Intent(Intent.ACTION_MEDIA_BUTTON)
mediaButtonIntent.component = mComponent
val mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast(
@ -151,7 +151,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
mediaSessionCompat = MediaSessionCompat(this, tag, mComponent, mediaButtonReceiverPendingIntent)
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonIntentReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent)
return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent)
}
})
mediaSessionCompat?.setMediaButtonReceiver(mediaButtonReceiverPendingIntent)

Loading…
Cancel
Save