什么是“类别”?在清单中是什么意思? [英] What does "category" in the manifest mean?

查看:1113
本文介绍了什么是“类别”?在清单中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档说您可以指定一个自定义类别。

The documentation says you can specify a custom category.


  • 何时,为什么以及如何做?

  • 有什么用?

推荐答案

据我所知,类别是android操作系统(和其他应用)的公共指令,代表您的应用应属于的不同类别。

The way I understand it, categories are public directives to the android operating system(and other apps) that represent different categories that your app should be a part of.

示例


  • 在主屏幕上点击启动器图标时,主应用程序会在每个已安装应用程序的清单中查找 HOME 类别-如果是,它将显示在应用程序抽屉中。

  • When the launcher icon is tapped on the home screen, the home application looks through every installed app's manifest for the HOME category -- and if so it displays it in the app drawer.

但是,还有更多。您可以在应用程序清单中指定类别,使系统知道您的应用程序可以处理意图类别。例如,通过放置 ALTERNATIVE 类别,系统中的其他应用程序知道您的应用程序可以处理该类别,而无需特别知道操作名称!在下面的示例中,定制意图类别通过该意图传递,该意图被过滤并编辑相应的对象(摘自Notes示例应用程序):

However, there's more. You can specify categories in your applications manifest that lets the system know that you application can handle the intent category. For example, by putting a ALTERNATIVE category, other apps in the system know that your app can handle that category without specifically knowing the action name! In the following example, custom intent categories are passed through this intent, which is filtered and the corresponding object gets edited(taken from the Notes example app):

<intent-filter android:label="@string/resolve_title">
 <action android:name="com.android.notepad.action.EDIT_TITLE" />
 <category android:name="android.intent.category.DEFAULT" />
 <category android:name="android.intent.category.ALTERNATIVE" />
 <category android:name="android.intent.category.SELECTED_ALTERNATIVE" />
 <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
</intent-filter>

通过在< activity />中注册该意图过滤器标记,您可以编辑注释。意图数据将包含注释,并且意图将被路由到该过滤器所注册的活动。

By registering this intent filter in an <activity /> tag, you can edit a "note". The intent data would contain the note, and the intent would get routed to the activity that this filter is registered in.

结论:

您使用自定义类别的确没有理由。它们是针对Android的,因此在应用程序使用中没有任何意义。但是,如果您选择使用它们,则可以在上述方法中使用它们。 它们提供了一些特定的语义规则,如果这些规则对您有用,那么可以随时使用它们(Hackbod)。

There isn't really a reason you'd use a custom category. They are for Android, and thus don't really make sense in application use. But, if you choose to use them, they can be used in the methods described above. "They provide some specific semantic rules, and if those rules are useful to you then feel free to use them"(Hackbod).

这篇关于什么是“类别”?在清单中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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