What does “category” in the manifest mean?

后端 未结 4 444
情书的邮戳
情书的邮戳 2021-02-05 17:40

The documentation says you can specify a custom category.

  • When, why and how would you do it?
  • What would be the use of it?
相关标签:
4条回答
  • 2021-02-05 18:21

    http://developer.android.com/guide/topics/intents/intents-filters.html

    Scroll down a bit and you should see a section under "Intent Objects"

    They basically describe certain special properties of an activity. for example, adding

    <category android:name="android.intent.category.HOME" />
    

    means that the app can be started on the phone's bootup

    0 讨论(0)
  • 2021-02-05 18:33

    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.

    Example

    • 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.

    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>
    

    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.

    In Conclusion:

    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).

    0 讨论(0)
  • 2021-02-05 18:35

    I'm kinda a noob to Android still, although I have programming experience otherwise.. It says a custom category in your own namespace. I'm guessing that if you are programming multiple apps and you want one app to run another app, you could use a custom category for your intent to force the phone to find your other app to catch the intent with?

    0 讨论(0)
  • 2021-02-05 18:40

    When you do not want to use the default category then use the custom category. Custom categories should use the package name as a prefix, to ensure that they are unique. Some information is provided on below link:
    http://developer.android.com/guide/topics/manifest/category-element.html Check the below link it has somewhat same question:
    Android custom categories

    0 讨论(0)
提交回复
热议问题