|
|
@@ -2,7 +2,6 @@ package io.legado.app.ui.javascript
|
|
|
|
|
|
import android.content.ActivityNotFoundException
|
|
|
import android.content.Intent
|
|
|
-import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
import android.widget.TextView
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
@@ -12,22 +11,21 @@ import io.legado.app.constant.AppLog
|
|
|
import io.legado.app.ui.widget.text.AccentTextView
|
|
|
import io.legado.app.utils.toastOnUi
|
|
|
|
|
|
-
|
|
|
class ConfirmationDialogActivity : AppCompatActivity() {
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
- // 必须先设置布局再获取控件
|
|
|
setContentView(R.layout.confirmation_dialog)
|
|
|
|
|
|
- // 正确顺序:先设置布局再获取视图
|
|
|
val messageView = findViewById<TextView>(R.id.message)
|
|
|
- val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
|
|
+ val toolbar = findViewById<Toolbar>(R.id.tool_bar)
|
|
|
val btnNegative = findViewById<AccentTextView>(R.id.btn_negative)
|
|
|
val btnPositive = findViewById<AccentTextView>(R.id.btn_positive)
|
|
|
|
|
|
- val url = intent?.dataString
|
|
|
- if (url.isNullOrBlank()) {
|
|
|
+ // 获取原始 Intent 的数据和 MIME 类型
|
|
|
+ val uri = intent?.data
|
|
|
+ val mimeType = intent?.getStringExtra("mimeType")
|
|
|
+ if (uri == null) {
|
|
|
finish()
|
|
|
return
|
|
|
}
|
|
|
@@ -36,16 +34,27 @@ class ConfirmationDialogActivity : AppCompatActivity() {
|
|
|
val sourceTag = intent.getStringExtra("sourceTag").takeIf { !it.isNullOrBlank() } ?: "当前来源"
|
|
|
messageView.text = "$sourceTag 正在请求跳转外部链接/应用,是否跳转?"
|
|
|
|
|
|
- // 设置其他组件
|
|
|
toolbar.setNavigationOnClickListener { finish() }
|
|
|
btnNegative.setOnClickListener { finish() }
|
|
|
btnPositive.setOnClickListener {
|
|
|
try {
|
|
|
- startActivity(
|
|
|
- Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {
|
|
|
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ // 创建目标 Intent 并设置类型
|
|
|
+ val targetIntent = Intent(Intent.ACTION_VIEW).apply {
|
|
|
+ // 同时设置 Data 和 Type
|
|
|
+ if (!mimeType.isNullOrBlank()) {
|
|
|
+ setDataAndType(uri, mimeType)
|
|
|
+ } else {
|
|
|
+ data = uri
|
|
|
}
|
|
|
- )
|
|
|
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否有应用可以处理
|
|
|
+ if (targetIntent.resolveActivity(packageManager) != null) {
|
|
|
+ startActivity(targetIntent)
|
|
|
+ } else {
|
|
|
+ toastOnUi(R.string.can_not_open)
|
|
|
+ }
|
|
|
} catch (e: ActivityNotFoundException) {
|
|
|
toastOnUi(R.string.can_not_open)
|
|
|
} catch (e: Exception) {
|