某些 Android 13 设备的深度链接出现错误

问题描述 投票:0回答:1

我在许多 Android 13 设备上遇到深层链接错误,主要是三星设备。

我在这些设备上没有收到任何错误。

  • Android - 13 - Galaxy Note20
  • 安卓 - 13 - 谷歌像素

我为

AndroidManifest.xml
做了必要的调整:

    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent>
    </queries>

...

       <intent-filter
           android:autoVerify="true"
           tools:targetApi="m">
           <action android:name="android.intent.action.VIEW" />

           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.BROWSABLE" />

           <data
              android:host="halilozel.com.tr"
              android:scheme="halilozel" />
      </intent-filter>

代码库:


fun getBrowserPackageName(context: Context): String? {
    val browserPackageName: MutableList<String> = ArrayList()
    try {
        val intent = Intent(Intent.ACTION_VIEW)
        intent.data = Uri.parse("http://www.aornzmenswqdt.mrgsscqsbgs")
        val pm = context.packageManager
        val browserList: List<ResolveInfo> = pm.queryIntentActivities(intent, 0)
        for (info in browserList) {
            browserPackageName.add(info.activityInfo.packageName)
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }

    return when {
        browserPackageName.isEmpty() -> null
        browserPackageName.contains(PACKAGE_NAME_CHROME) -> PACKAGE_NAME_CHROME
        browserPackageName.contains(PACKAGE_NAME_OPERA) -> PACKAGE_NAME_OPERA
        else -> browserPackageName[0]
    }
}

fun Context.getBrowserIntent(url: String): Intent {
    val browserPackageName = getBrowserPackageName(this)
    if (browserPackageName != null) {
        val intent = packageManager.getLaunchIntentForPackage(browserPackageName)
        if (intent != null) {
            return intent.apply { data = Uri.parse(url) }
        }
    }

    val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://"))
    val resolveInfo = packageManager.resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY)
    if (resolveInfo != null) {
        val packageName: String = resolveInfo.activityInfo.packageName
        val intent = packageManager.getLaunchIntentForPackage(packageName)
        if (intent != null) {
            return intent.apply { data = Uri.parse(url) }
        }
    }
    return Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER).apply { data = Uri.parse(url) }
}

Android 13 有什么样的更新?

android deep-linking android-deep-link android-13 android-13-deeplink
1个回答
0
投票

一些浏览器在使用时放弃处理作为 Android 13 数据传递的 uris

Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)

https://issuetracker.google.com/issues/243678703

© www.soinside.com 2019 - 2024. All rights reserved.