Skip to content

fix: add Intent flag on open browser#599

Merged
MakinoharaShoko merged 2 commits into
OpenWebGAL:devfrom
nini22P:dev
May 10, 2026
Merged

fix: add Intent flag on open browser#599
MakinoharaShoko merged 2 commits into
OpenWebGAL:devfrom
nini22P:dev

Conversation

@nini22P

@nini22P nini22P commented May 9, 2026

Copy link
Copy Markdown
Contributor

解决某些安卓设备无法打开浏览器的问题

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a BrowserUtils utility to centralize browser intent creation and error handling, which is integrated into MainScreen.kt. It also updates intent flags in Notification.kt. Review feedback recommends removing an unused import in BrowserUtils.kt, refactoring the intent creation into a reusable method to eliminate logic duplication between BrowserUtils and Notification.kt, and improving variable naming for better code clarity.

import android.content.Context
import android.content.Intent
import android.widget.Toast
import androidx.browser.customtabs.CustomTabsIntent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

导入了未使用的 CustomTabsIntent,建议将其移除以保持代码整洁。

Comment on lines +12 to +27
fun openBrowser(context: Context, url: String) {
val uri = url.toUri()
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
addCategory(Intent.CATEGORY_BROWSABLE)
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
try {
context.startActivity(intent)
} catch (e2: ActivityNotFoundException) {
Toast.makeText(
context,
context.getString(R.string.could_not_open_browser),
Toast.LENGTH_SHORT
).show()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议将 Intent 的创建逻辑提取到一个独立的方法中,这样可以在 Notification.kt 等其他地方复用,避免逻辑重复。同时,建议将异常变量名 e2 修改为更符合规范的 e

    fun createBrowserIntent(url: String): Intent =
        Intent(Intent.ACTION_VIEW, url.toUri()).apply {
            addCategory(Intent.CATEGORY_BROWSABLE)
            setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }

    fun openBrowser(context: Context, url: String) {
        try {
            context.startActivity(createBrowserIntent(url))
        } catch (e: ActivityNotFoundException) {
            Toast.makeText(
                context,
                context.getString(R.string.could_not_open_browser),
                Toast.LENGTH_SHORT
            ).show()
        }
    }

Comment on lines +80 to +83
Intent(Intent.ACTION_VIEW, context.getString(R.string.local_url).toUri()).apply {
addCategory(Intent.CATEGORY_BROWSABLE)
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

此处的 Intent 创建逻辑与 BrowserUtils 中的重复。建议复用 BrowserUtils.createBrowserIntent 以保持逻辑统一。注意:由于包路径不同,建议使用全限定名或在文件顶部添加相应的 import。

            com.openwebgal.terre.utils.BrowserUtils.createBrowserIntent(context.getString(R.string.local_url))

@nini22P nini22P linked an issue May 9, 2026 that may be closed by this pull request
@MakinoharaShoko MakinoharaShoko merged commit 63c9655 into OpenWebGAL:dev May 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] webgal 安卓端无法直接打开浏览器

2 participants