簡體   English   中英

Android 深度鏈接不從瀏覽器加載,即使是簡單的教程

[英]Android deep linking not loading from browser, even from simple tutorial

我無法在我的 android 應用程序中使用深度鏈接,所以我找到了最簡單的教程,但當我單擊鏈接時它仍然只是打開瀏覽器。 所有這些都是從我的代碼而不是教程中粘貼的,以防我粘貼錯誤。 即使這樣

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.DeepLinkTest">
    <activity android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- as we want to open main activity from our link so we are specifying
            only in main activity or we can specify that in different activity as well -->
        <!-- on below line we are adding intent filter to our MainActivity -->
        <intent-filter>
            <!-- below line is to set the action to our intent to view -->
            <action android:name="android.intent.action.VIEW" />

            <!-- on below line we are adding a default category to our intent -->
            <category android:name="android.intent.category.DEFAULT" />

            <!-- on below line we are adding a category to make our app browsable -->
            <category android:name="android.intent.category.BROWSABLE" />

            <!-- on below line we are specifying the host name and
                the scheme type from which we will be calling our app -->
            <data
                android:host="www.chaitanyamunje.com"
                android:scheme="https" />
        </intent-filter>

        <!-- below is the same filter as above just the scheme is changed to http -->
        <!-- so we can open our app with the url starting with https and http as well -->
        <intent-filter>
            <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.chaitanyamunje.com"
                android:scheme="http" />
        </intent-filter>
    </activity>
</application>

主活動.kt

package me.paxana.deeplinktest

import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

class MainActivity : AppCompatActivity() {

  // creating a variable for our text view
  private lateinit var messageTV: TextView
  private var uri: Uri? = null

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // initializing our variable
    messageTV = findViewById(R.id.idTVMessage)
    // getting the data from our intent in our uri.
    uri = intent.data

    // checking if the uri is null or not.
    if (uri != null) {
      // if the uri is not null then we are getting
      // the path segments and storing it in list.
      val parameters = uri!!.pathSegments

      // after that we are extracting string
      // from that parameters.
      val param = parameters[parameters.size - 1]

      // on below line we are setting that
      // string to our text view which
      // we got as params.
      messageTV.text = param
    }
  }
}

使用android工作室的App Link Testing功能加載https的結果://www.chaitanyamunje.com/hello/GeeksForGeeks

瀏覽器顯示“無法訪問此站點。檢查 chaitanyamunje.com 中是否有拼寫錯誤。DNS_PROBE_FINISHED_NXDOMAIN。”

我多次遇到的一個非常普遍的問題。 人們經常在android:scheme中添加https來確保 url 安全。 我不知道為什么不打開應用程序。 但是,就我而言,刪除該 Intent 過濾器會使該應用程序為我打開。

讓我知道它是否有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM