gpt4 book ai didi

Android:选择用于打开链接的应用程序

转载 作者:行者123 更新时间:2023-11-29 15:12:57 25 4
gpt4 key购买 nike

在 Android 应用程序中,选择应用程序以打开链接或执行其他操作的选择通常留给用户,即框架用户选择应用做某事。

例如,假设您有一条推文的链接,您可以选择:

  • 推特
  • Chrome
  • 网络浏览器

允许用户选择打开链接的应用程序而不是本地应用程序的原因是什么?

最佳答案

根据 this :

An implicit intent specifies an action that can invoke any app on the device able to perform the action. Using an implicit intent is useful when your app cannot perform the action, but other apps probably can and you'd like the user to pick which app to use.

this :

The real power of intents lies in the concept of implicit intents. An implicit intent simply describes the type of action to perform (and, optionally, the data upon which you’d like to perform the action) and allows the system to find a component on the device that can perform the action and start it. If there are multiple components that can perform the action described by the intent, then the user selects which one to use.

想法是,在 Android 中,开发人员可以让他的应用程序使用设备上的另一个应用程序来执行某些任务,而不必在他们自己的应用程序中重新创建相同的功能。通常,有多个应用程序可以执行相同的任务,因此 Android 允许用户选择他们要用于该任务的应用程序。

基本上,该框架试图提供最通用的方式来完成任务:如果官方 Twitter 应用程序不存在,那么您总是有 Chrome.

这是在代码中完成的方式 here .

关于Android:选择用于打开链接的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28540667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com