Android

您所在的位置:网站首页 打开文件分享app Android

Android

2024-07-17 04:31| 来源: 网络整理| 查看: 265

一、基础知识

我们需要让自己的 App 能打开文件或者接受其它 App 分享出来的文件,实际上就是 App 隐式调用的一种应用,需要使用 、、 等标签,在 AndroidManifest.xml 中定义我们的 App 可以进行的操作,以及类型限制。

标签

官方介绍:

Specifies the types of intents that an activity, service, or broadcast receiver can respond to. An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

Most of the contents of the filter are described by its , , and subelements.

标签,是用来过滤我们 App 可以进行的活动和接受的广播。里面可以声明作用范围(使用 MimeType )以及 URL 地址(使用 scheme)等。

可以理解为我们对于当前 Activity 可以接受的 Intent 的过滤器,里面的标签限制了我们能执行的动作,如 就是我们在创建 Intent 时,setAction() 设置进去的动作。

标签

官方介绍:

Adds an action to an intent filter. An element must contain one or more elements. If there are no elements in an intent filter, the filter doesn’t accept any Intent objects. See Intents and Intent Filters for details on intent filters and the role of action specifications within a filter.

标签,是用来指定 App 可以执行的 Intent 的操作类型。比如 android.intent.action.ACTION_SEND 表示当前 Activity 可以接受“分享”的操作。

一个 标签下,至少应该包含一个 标签,并且如果 标签的内容和其它的标签冲突,比如 ACTION_SEND 和 这个标签的内容就是冲突的,最终会导致这个 的定义失效。

我们应该尽量不要在 中定义多个 ,避免相互冲突。

标签

官方介绍:

Adds a category name to an intent filter. See Intents and Intent Filters for details on intent filters and the role of category specifications within a filter.

标签,用来声明接受的 Intent 的类型。

为了接收隐式 Intent,必须将 CATEGORY_DEFAULT 类别包括在 Intent 过滤器中。 方法 startActivity() 和 startActivityForResult() 将按照已申明 CATEGORY_DEFAULT 类别的方式处理所有 Intent。 如果未在 Intent 过滤器中声明此类别,则隐式 Intent 不会解析为您的 Activity。

标签

标签可以包含的内容:

官方介绍:

Adds a data specification to an intent filter. The specification can be just a data type (the mimeType attribute), just a URI, or both a data type and a URI. A URI is specified by separate attributes for each of its parts:

://:[||]

These attributes that specify the URL format are optional, but also mutually dependent:

If a scheme is not specified for the intent filter, all the other URI attributes are ignored. If a host is not specified for the filter, the port attribute and all the path attributes are ignore


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3