我是靠谱客的博主 生动缘分,最近开发中收集的这篇文章主要介绍Android Manifest.xml 之 Intent-filter,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

开始前先post出最简单的AndroidManifest.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
 
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.actionbarcompat.basic"
    android:versionCode="1"
    android:versionName="1.0">
 
    <!-- ActionBarCompat provides an Action Bar from API v7 onwards -->
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat"
        android:allowBackup="true">
 
        <activity android:name=".MainActivity">
            <!-- Launcher Intent filter -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

  Android核心组件(Activity,Service,Broadcast Receiver)通过Intent来激活,Intent描述了actioin,data等信息;在某个component被激活前,要提前写好该component能处理那些Intent,这就需要在AndroidManifest.xml 里<intent-filter></intent-filter>标签内写好。

      <intent-filter>...</intent-filter>省略号可以有以下内容:

      

  • action -- The general action to be performed, such as ACTION_VIEWACTION_EDITACTION_MAIN, etc.

  • data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri.

  • category -- Gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.

  • type -- Specifies an explicit type (a MIME type) of the intent data. Normally the type is inferred from the data itself. By setting this attribute, you disable that evaluation and force an explicit type.

  • component -- Specifies an explicit name of a component class to use for the intent. Normally this is determined by looking at the other information in the intent (the action, data/type, and categories) and matching that with a component that can handle it. If this attribute is set then none of the evaluation is performed, and this component is used exactly as is. By specifying this attribute, all of the other Intent attributes become optional.

  • extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.

转载于:https://www.cnblogs.com/songwanzi/p/3764145.html

最后

以上就是生动缘分为你收集整理的Android Manifest.xml 之 Intent-filter的全部内容,希望文章能够帮你解决Android Manifest.xml 之 Intent-filter所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(45)

评论列表共有 0 条评论

立即
投稿
返回
顶部