与其他应用交互
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 应用一般具有若干个 activity。每个 activity 会显示一个界面,用户可通过该界面执行特定任务,如查看地图或拍照。如需将用户从一个 activity 转至另一个 activity,应用必须使用 Intent
来定义其用于执行操作的“意图”。当您使用 startActivity()
等方法将 Intent
传递至系统时,系统会使用 Intent
来识别和启动相应的应用组件。使用 intent 甚至可以让您的应用启动另一个应用包含的 activity。
Intent
可以为“显式”,以便启动特定 Activity
实例;也可为“隐式”,以便启动任何可以处理预期操作(例如“拍摄照片”)的组件。
本指南中的主题介绍了如何使用 Intent
与其他应用进行一些基本交互,例如启动另一个应用、接收来自该应用的结果,以及让您的应用能够响应其他应用的 intent。
主题
- 将用户转到其他应用
- 向您展示如何创建隐式 intent,以启动可执行操作的其他应用。
- 获取 activity 的结果
- 向您展示如何启动另一 activity 并接收该 activity 的结果。
- 允许其他应用启动您的 activity
- 向您展示如何通过定义声明您的应用接受的隐式 intent 的 intent 过滤器,使您应用中的 activity 可供其他应用使用。
- Android 上的软件包可见性过滤
- 向您展示如何让默认处于不可见状态的其他应用对您的应用可见。仅适用于以 Android 11(API 级别 30)或更高版本为目标平台的应用。
- 在软件包可见性有限的情况下执行常见用例
- 向您展示几种类型的应用交互,这些交互可能需要您更新应用的清单文件,才能让其他应用对您的应用可见。仅适用于以 Android 11(API 级别 30)或更高版本为目标平台的应用。
- 限制在设备端 Android 容器中加载
- 向您展示如何限制您的 Play 商店应用在模拟 Android 环境应用(也称为设备端 Android 容器)中加载。
有关本页主题的更多信息,请参阅以下内容:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-10。
[null,null,["最后更新时间 (UTC):2025-02-10。"],[],[],null,["# Interact with other apps\n\nAn Android app typically has several [activities](/guide/components/activities). Each activity displays a\nuser interface that lets the user perform a specific task, such as viewing a map or taking a photo.\nTo take the user from one activity to another, your app must use an [Intent](/reference/android/content/Intent) to define your app's \"intent\" to do something. When you pass an\n`Intent` to the system with a method\nsuch as [startActivity()](/reference/android/app/Activity#startActivity(android.content.Intent)),\nthe system uses the `Intent` to identify and start the appropriate app component. Using intents\neven lets your app start an activity that is contained in a separate app.\n\nAn `Intent` can be *explicit* , to start\na specific [Activity](/reference/android/app/Activity) instance,\nor *implicit*, to start any\ncomponent that can handle the intended action, such as \"capture a photo.\"\n\nThe topics in this guide show you how to use an `Intent` to perform some basic\ninteractions with other apps, such as starting another app, receiving a result from that app, and\nmaking your app able to respond to intents from other apps.\n\nTopics\n------\n\n**[Sending the user to another app](/training/basics/intents/sending)**\n: Shows you how to create implicit intents to launch other apps that can perform an\n action.\n\n**[Get a result from an activity](/training/basics/intents/result)**\n: Shows you how to start another activity and receive a result from the activity.\n\n**[Allow other apps to start your activity](/training/basics/intents/filters)**\n: Shows you how to make activities in your app open for use by other apps by defining\n intent filters that declare the implicit intents your app accepts.\n\n**[Package visibility filtering on Android](/training/basics/intents/package-visibility)**\n: Shows you how to make other apps visible to your app if they\n aren't visible by default. Applies only to apps that target Android 11\n (API level 30) or higher.\n\n**[Fulfill common use cases while\nhaving limited package visibility](/training/basics/intents/package-visibility-use-cases)**\n: Shows several types of app interactions that might require you to update\n your app's manifest file so that other apps are visible to your app.\n Applies only to apps that target Android 11 (API level 30) or higher.\n\n**[Limit loading in on-device Android containers](/training/basics/intents/limit-play-loading)**\n: Shows you how to limit your Play Store app from loading in a simulated\n Android environment app, also known as an on-device Android container.\n\nFor additional information about the topics on this page, see the following:\n\n- [Sharing simple data](/training/sharing)\n- [Sharing files](/training/secure-file-sharing)\n- [Integrating Application with Intents](http://android-developers.blogspot.com/2009/11/integrating-application-with-intents.html) blog post\n- [Intents and Intent\n Filters](/guide/components/intents-filters)"]]