diff --git a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt index 92a4b9320..8dbb836a9 100644 --- a/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/MediaButtonReceiver.kt @@ -31,6 +31,12 @@ import kotlinx.coroutines.withContext class MediaButtonReceiver : BroadcastReceiver() { + override fun onReceive(context: Context, intent: Intent) { + if (handleIntent(context, intent) && isOrderedBroadcast) { + abortBroadcast() + } + } + companion object { fun handleIntent(context: Context, intent: Intent): Boolean { @@ -55,7 +61,7 @@ class MediaButtonReceiver : BroadcastReceiver() { return true } - private fun readAloud(context: Context) { + fun readAloud(context: Context) { when { BaseReadAloudService.isRun -> if (BaseReadAloudService.isPlay()) { ReadAloud.pause(context) @@ -97,10 +103,4 @@ class MediaButtonReceiver : BroadcastReceiver() { } } - override fun onReceive(context: Context, intent: Intent) { - if (handleIntent(context, intent) && isOrderedBroadcast) { - abortBroadcast() - } - } - } diff --git a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt index 6d76736d5..1e08c3c6f 100644 --- a/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt +++ b/app/src/main/java/io/legado/app/receiver/SharedReceiverActivity.kt @@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity import io.legado.app.ui.book.search.SearchActivity import io.legado.app.ui.main.MainActivity import io.legado.app.utils.startActivity +import splitties.init.appCtx class SharedReceiverActivity : AppCompatActivity() { @@ -19,25 +20,30 @@ class SharedReceiverActivity : AppCompatActivity() { } private fun initIntent() { - if (Intent.ACTION_SEND == intent.action && intent.type == receivingType) { - intent.getStringExtra(Intent.EXTRA_TEXT)?.let { - if (openUrl(it)) { - startActivity { - putExtra("key", it) + when { + Intent.ACTION_SEND == intent.action && intent.type == receivingType -> { + intent.getStringExtra(Intent.EXTRA_TEXT)?.let { + if (openUrl(it)) { + startActivity { + putExtra("key", it) + } } } } - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && Intent.ACTION_PROCESS_TEXT == intent.action - && intent.type == receivingType - ) { - intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { - if (openUrl(it)) { - startActivity { - putExtra("key", it) + Build.VERSION.SDK_INT >= Build.VERSION_CODES.M + && Intent.ACTION_PROCESS_TEXT == intent.action + && intent.type == receivingType -> { + intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)?.let { + if (openUrl(it)) { + startActivity { + putExtra("key", it) + } } } } + intent.getStringExtra("action") == "mediaButton" -> { + MediaButtonReceiver.readAloud(appCtx) + } } } diff --git a/app/src/main/res/xml/shortcuts.xml b/app/src/main/res/xml/shortcuts.xml index 7d389f78e..6e16843c7 100644 --- a/app/src/main/res/xml/shortcuts.xml +++ b/app/src/main/res/xml/shortcuts.xml @@ -21,6 +21,26 @@ + + + + + + + + +