您可以添加更多属性,以进一步细化 Activity 接受的 URI 类型。例如,您可能拥有多个接受相似 URI 的 activity,这些 URI 只是路径名称有所不同。在这种情况下,请使用 android:path 属性或其 pathPattern 或 pathPrefix 变体区分系统应针对不同 URI 路径打开哪个 activity。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-27。"],[],[],null,["When a clicked link or programmatic request invokes a web URI intent, the Android system\ntries each of the following actions, in sequential order, until the request succeeds:\n\n1. Open the user's preferred app that can handle the URI, if one is designated.\n2. Open the only available app that can handle the URI.\n3. Allow the user to select an app from a dialog.\n\nFollow the steps below to create and test links to your content. You can also use the\n[App Links Assistant](/studio/write/app-link-indexing) in Android Studio to add\nAndroid App Links.\n\n**Note:** Starting in Android 12 (API level 31), a generic\nweb intent resolves to an activity in your app only if your app is approved for\nthe specific domain contained in that web intent. If your app isn't approved for\nthe domain, the web intent resolves to the user's default browser app\ninstead.\n\nAdd intent filters for incoming links\n\nTo create a link to your app content, add an intent filter that\ncontains these elements and attribute values in your manifest:\n\n[`\u003caction\u003e`](/guide/topics/manifest/action-element)\n: Specify the [ACTION_VIEW](/reference/android/content/Intent#ACTION_VIEW) intent action so\n that the intent filter can be reached from Google Search.\n\n[`\u003cdata\u003e`](/guide/topics/manifest/data-element)\n: Add one or more [`\u003cdata\u003e`](/guide/topics/manifest/data-element)\n tags, each of which represents a URI format that resolves to the activity. At minimum, the\n [`\u003cdata\u003e`](/guide/topics/manifest/data-element) tag must include\n the [`android:scheme`](/guide/topics/manifest/data-element#scheme)\n attribute.\n\n You can add more attributes to further refine the type of URI that the activity accepts. For\n example, you might have multiple activities that accept similar URIs, but which differ simply\n based on the path name. In this case, use the\n [`android:path`](/guide/topics/manifest/data-element#path) attribute\n or its `pathPattern` or `pathPrefix` variants to differentiate which\n activity the system should open for different URI paths.\n\n[`\u003ccategory\u003e`](/guide/topics/manifest/category-element)\n: Include the [BROWSABLE](/reference/android/content/Intent#CATEGORY_BROWSABLE)\n category. It is required in order for the intent filter to be accessible from a web\n browser. Without it, clicking a link in a browser cannot resolve to your app.\n\n Also include the [DEFAULT](/reference/android/content/Intent#CATEGORY_DEFAULT) category.\n This allows your app to respond to implicit intents. Without this, the activity can be started\n only if the intent specifies your app component name.\n\nThe following XML snippet shows how you might specify an intent filter\nin your manifest for deep linking. The URIs `\"example://gizmos\"` and\n`\"http://www.example.com/gizmos\"` both resolve to this activity. \n\n```xml\n\u003cactivity\n android:name=\"com.example.android.GizmosActivity\"\n android:label=\"@string/title_gizmos\" \u003e\n \u003cintent-filter android:label=\"@string/filter_view_http_gizmos\"\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n \u003c!-- Accepts URIs that begin with \"http://www.example.com/gizmos” --\u003e\n \u003cdata android:scheme=\"http\"\n android:host=\"www.example.com\"\n android:pathPrefix=\"/gizmos\" /\u003e\n \u003c!-- note that the leading \"/\" is required for pathPrefix--\u003e\n \u003c/intent-filter\u003e\n \u003cintent-filter android:label=\"@string/filter_view_example_gizmos\"\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n \u003c!-- Accepts URIs that begin with \"example://gizmos” --\u003e\n \u003cdata android:scheme=\"example\"\n android:host=\"gizmos\" /\u003e\n \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\n\nNotice that the two intent filters only differ by the `\u003cdata\u003e` element.\nAlthough it's possible to include multiple `\u003cdata\u003e` elements in the same filter,\nit's important that you create separate filters when your intention is to declare unique\nURLs (such as a specific combination of `scheme` and `host`), because\nmultiple `\u003cdata\u003e` elements in the same intent filter are actually merged together\nto account for all variations of their combined attributes. For example, consider the following:\n\n```xml\n\u003cintent-filter\u003e\n ...\n \u003cdata android:scheme=\"https\" android:host=\"www.example.com\" /\u003e\n \u003cdata android:scheme=\"app\" android:host=\"open.my.app\" /\u003e\n\u003c/intent-filter\u003e\n```\n\nIt might seem as though this supports only `https://www.example.com` and\n`app://open.my.app`. However, it actually supports those two, plus these:\n`app://www.example.com` and `https://open.my.app`.\n\n**Caution:** If multiple activities contain intent filters that resolve to the same\nverified Android App Link, then there's no guarantee as to which activity\nhandles the link.\n\nOnce you've added intent filters with URIs for activity content to your app\nmanifest, Android is able to route any [Intent](/reference/android/content/Intent)\nthat has matching URIs to your app at runtime.\n\nTo learn more about defining intent filters, see\n[Allow Other Apps to Start Your Activity](/training/basics/intents/filters).\n\nRead data from incoming intents\n\nOnce the system starts your activity through an intent filter, you can\nuse data provided by the [Intent](/reference/android/content/Intent) to determine what you need to render. Call\nthe [getData()](/reference/android/content/Intent#getData()) and\n[getAction()](/reference/android/content/Intent#getAction()) methods to retrieve the data and\naction associated with the incoming [Intent](/reference/android/content/Intent). You can\ncall these methods at any time during the lifecycle of the activity, but you\nshould generally do so during early callbacks such as\n[onCreate()](/reference/android/app/Activity#onCreate(android.os.Bundle)) or\n[onStart()](/reference/android/app/Activity#onStart()).\n\nHere's a snippet that shows how to retrieve data from an\n[Intent](/reference/android/content/Intent): \n\nKotlin \n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n super.onCreate(savedInstanceState)\n setContentView(R.layout.main)\n\n val action: String? = intent?.action\n val data: Uri? = intent?.data\n}\n```\n\nJava \n\n```java\n@Override\npublic void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.main);\n\n Intent intent = getIntent();\n String action = intent.getAction();\n Uri data = intent.getData();\n}\n```\n\nFollow these best practices to improve the user's experience:\n\n- The deep link should take users directly to the content, without any prompts, interstitial pages, or logins. Make sure that users can see the app content even if they never previously opened the application. It is okay to prompt users on subsequent interactions or when they open the app from the Launcher.\n- Follow the design guidance described in [Navigation with Back and Up](/guide/navigation/navigation-principles) so that your app matches users' expectations for backward navigation after they enter your app through a deep link.\n\nTest your deep links\n\nYou can use the [Android Debug\nBridge](/tools/help/adb) with the activity manager (am) tool to test that the intent filter\nURIs you specified for deep linking resolve to the correct app activity. You\ncan run the adb command against a device or an emulator.\n\nThe general syntax for testing an intent filter URI with adb is: \n\n```\n$ adb shell am start\n -W -a android.intent.action.VIEW\n -d \u003cURI\u003e \u003cPACKAGE\u003e\n```\n\nFor example, the command below tries to view a target app activity that\nis associated with the specified URI. \n\n```\n$ adb shell am start\n -W -a android.intent.action.VIEW\n -d \"example://gizmos\" com.example.android\n```\n| **Note:** When defining a collection of primitive types in a route, such as `@Serializable data class Product(val colors: List`), the automatically generated deep link URL format is `basePath?colors={value}`. If you attempt to specify a URI with multiple query params (for example, `basepath?colors=red&colors=blue`), you must escape the ampersand (for example, `basepath?colors=red\\&colors=blue`).\n\n\nThe manifest declaration and intent handler you set above define the connection between your app\nand a website and what to do with incoming links. However, in\norder to have the system treat your app as the default handler for a set of URIs, you must\nalso request that the system verify this connection.\nThe [next lesson](/training/app-links/verify-android-applinks) explains how to\nimplement this verification.\n\nTo learn more about intents and app links, see the following resources:\n\n- [Intents and Intent Filters](/guide/components/intents-filters)\n- [Allow Other Apps to Start Your Activity](/training/basics/intents/filters)\n- [Add Android App Links with Android Studio](/studio/write/app-link-indexing)"]]