首页 > 解决方案 > 如何在不询问用户选择的情况下直接登陆应用程序 android 深层链接

问题描述

我创建了一个深层链接,但问题是它以“打开或使用其他应用程序”的形式打开一个对话框

我不想让用户决定选择对话框。我想直接打开我的应用程序。这是代码。

<activity android:name=".DeepLinkingActivity">
    <intent-filter
        android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />

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

        <data
            android:host="www.google.com"
            android:pathPrefix="/help"
            android:scheme="https" />
    </intent-filter>
</activity>

class DeepLinkingActivity : AppCompatActivity() {
    var datas: Uri? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_deep_link)
    }

    override fun onResume() {
        super.onResume()
        var intent = intent
        datas = intent.data
        Log.v("TestingsDatas", "" + datas)

    }
}

标签: androidkotlinapplinksandroid-deep-link

解决方案


如果您不想看到该对话框。您必须验证您尝试导航的主机是否与您的应用程序相关。在此示例中,主机是“www.google.com”。起初,这个 url 必须属于你。让我们假设您拥有“www.example.com” 您将把一个数字资产链接 JSON 文件放到下面的路径中:

https://www.example.com/.well-known/assetlinks.json

其内容应如下所示,包括您的包名称和您的密钥库(用于 Google Play)sha256 指纹:

[{
  "relation": ["delegate_permission/common.handle_all_urls"],
  "target": {
    "namespace": "android_app",
    "package_name": "com.example",
    "sha256_cert_fingerprints":
    ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
  }
}]

比你看不到那个对话框。更多详情:https ://developer.android.com/training/app-links/verify-site-associations.html


推荐阅读