安卓:选择用来打开链接的应用程序 [英] Android: Choose the application with which to open a link

查看:287
本文介绍了安卓:选择用来打开链接的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android应用程序,选择一个应用程序来打开链接或做一些其他的动作往往选择留给了用户,也就是框架的允许的用户的选择的应用程序做一些事情。

In Android applications, often the choice of selecting an app to open a link or do some other action is left to the user, i.e. the framework lets the user choose the app to do something.

举例来说,假设你有一个链接到一个鸣叫,和你被允许之间进行选择:

For example, say you have a link to a tweet, and you are allowed to choose between:


  • 微博


  • Web浏览器

什么是允许用户选择用来打开一个链接,而不是原生应用程序的应用的原因?

What is the reason that the user is allowed to choose the application with which to open a link rather than with native application?

推荐答案

据的这个

这是隐含的意图指定可以调用的任何应用程序的操作
  设备能够执行的操作。使用隐式意图是有用
  当你的应用程序无法执行的操作,但其他应用程序可能会
  你想在用户选择要使用的应用程序。

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.

意图的真正威力在于隐含意图的概念。一个
  隐式意图只是简单地描述要执行的操作的类型(和,
  可选,在你想执行操作的数据)和
  允许系统来查找可以执行设备上的组件
  的行动,并启动它。如果有多个组件可以
  执行由意图描述的动作,则用户选择
  要使用哪一个。

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允许用户选择哪些应用程序的 <他们/ em>的要使用该任务多个应用程序。

The idea is that in Android, a developer can let his app use another app on the device to perform some task, instead of having to recreate the same functionality within their own app. Often, there is more than one app that can perform the same task, and so Android allows the user to select which app they want to use for that task.

基本上,该框架试图提供最一般的得到一个完成任务的方式:如果官方微博应用程序是不是present,那么你总是有

Basically, the framework attempts to provide the most general way of getting a task done: if the official Twitter app is not present, then you always have Chrome.

这是在code做的方法显示这里

The way this is done in code is shown here.

这篇关于安卓:选择用来打开链接的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆