android系统框图ppt

作者:android系统框图ppt 来源:未知 2021-11-21 04:50   阅读:

PPT内容这是android系统框图ppt,包括了Android的源代码结构介绍,应用程序,应用程序框架,系统运行库(Libraries),L

android系统框图ppt

PPT内容

这是android系统框图ppt,包括了Android的源代码结构介绍,应用程序,应用程序框架,系统运行库(Libraries),Linux 内核,android的四大主件,Activity的生命周期,活动,服务,Service范例,广播接收器,Broadcast Receiver使用,内容提供者,Content Provider的用法,意图,Intent对象,Intent消息机制,显式Intent用法,隐式Intent用法,IntentFilter的匹配规则,Gallery里的AndroidManifest.xml,AndroidManifest.xml综述等内容,欢迎点击下载。

Andorid整体框架简介
主讲人:金腾飞/kingfly
Android的源代码结构介绍
|-- Makefile   全局的Makefile
|-- bionic   bionic C库
|-- bootable   启动引导相关代码
|-- build  存放系统编译规则及generic等基础开发包配置
|-- cts     Android兼容性测试套件标准
|-- dalvik    dalvik JAVA虚拟机
|-- development  应用程序开发相关
|-- external    android使用的一些开源的模组
|-- frameworks   核心框架
|-- hardware   部分厂家开源的硬解适配层HAL代码
|-- out    编译完成后的代码输出与此目录
|-- packages   应用程序包
|-- prebuilt    x86和arm架构下预编译的一些资源
|-- sdk     sdk及模拟器
|-- system   底层文件系统库、应用及组件——C语言
|-- vendor   厂商定制代码
Applications                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
Android装配一个核心应用程序集合,包括电子邮件客户端、SMS程序、日历、地图、浏览器、联系人和其他设置。
这些应用的主要分布区域包括:
android/packages/apps
这里的应用主要是: Browser,Calculator,Email,Music,MMS,Phone,Settings等。
android/packages/wallpapers
这里主要放的是Android自带的动态墙纸。
android/prebuilt/android-arm/android-app/app
这里主要是放Android预装的软件的apk。
android/vendor
这里主要我们自己写的应用,目前没有。
android/frameworks/base/packages/SystemUI
这里主要放置SystemUi的相关代码。
android/frameworks/base/core/res
这里主要是放置系统相关的资源。
Application Framework
开发人员也可以完全访问核心应用程序所使用的API框架。该应用程序的架构设计简化了组件的重用;任何一个应用程序都可以发布它的功能块并且任何其它的应用程序都可以使用其所发布的功能块(不过得遵循框架的安全性限制)。同样,该应用程序重用机制也使用户可以方便的替换程序组件。
隐藏在每个应用后面的是一系列的服务和系统, 其中包括;
* 丰富而又可扩展的视图(Views),可以用来构建应用程序, 它包括列表(lists),网格(grids),文本框(text boxes),按钮(buttons), 甚至可嵌入的web浏览器。
* 内容提供器(Content Providers)使得应用程序可以访问另一个应用程序的数据(如联系人数据库), 或者共享它们自己的数据
* 资源管理器(Resource Manager)提供 非代码资源的访问,如本地字符串,图形,和布局文件( layout files )。
* 通知管理器 (Notification Manager) 使得应用程序可以在状态栏中显示自定义的提示信息。
* 活动管理器( Activity Manager) 用来管理应用程序生命周期并提供常用的导航回退功能。
系统运行库(Libraries)
1)程序库
Android 包含一些C/C++库,这些库能被Android系统中不同的组件使用。它们通过 Android 应用程序框架为开发者提供服务。以下是一些核心库:
系统 C 库 - 一个从 BSD 继承来的标准 C 系统函数库( libc ), 它是专门为基于 embedded linux 的设备定制的。
媒体库 - 基于 PacketVideo OpenCORE;该库支持多种常用的音频、视频格式回放和录制,同时支持静态图像文件。编码格式包括MPEG4, H.264, MP3, AAC, AMR, JPG, PNG 。
 Surface Manager - 对显示子系统的管理,并且为多个应用程序提 供了2D和3D图层的无缝融合。
 LibWebCore - 一个最新的web浏览器引擎用,支持Android浏览器和一个可嵌入的web视图。
 SGL - 底层的2D图形引擎
 3D libraries - 基于OpenGL ES 1.0 APIs实现;该库可以使用硬件 3D加速(如果可用)或者使用高度优化的3D软加速。
FreeType -位图(bitmap)和矢量(vector)字体显示。
 SQLite - 一个对于所有应用程序可用,功能强劲的轻型关系型数据库引擎。
2)Android 运行库
Android 包括了一个核心库,该核心库提供了JAVA编程语言核心库的大多数功能。
每一个Android应用程序都在它自己的进程中运行,都拥有一个独立的Dalvik虚拟机实例。Dalvik被设计成一个设备可以同时高效地运行多个虚拟系统。 Dalvik虚拟机执行(.dex)的Dalvik可执行文件,该格式文件针对小内存使用做了优化。同时虚拟机是基于寄存器的,所有的类都经由JAVA编译器编译,然后通过SDK中 的 “dx” 工具转化成.dex格式由虚拟机执行。
Dalvik虚拟机依赖于linux内核的一些功能,比如线程机制和底层内存管理机制。
Linux 内核
Android 的核心系统服务依赖于 Linux 2.6 内核,如安全性,内存管理,进程管理, 网络协议栈和驱动模型。 Linux 内核也同时作为硬件和软件栈之间的抽象层。
android的四大主件
Activity
Service
Broadcast Receiver
Content Provider
android的四大主件
Activity, Service, Broadcast Receiver 都是通过被称之为意图(intent)的消息运行。Intent messaging is a facility for late run-time binding between components in the same or different applications. 意图本身一个 Intent 对象,它保存了对要执行操作的抽象描述—对于broadcasts来说,则表示对已经发生并且正要报告的操作。对这下三种组件,发送intents分别有不同的机制。
传递一个Intent对象到 Context.startActivity(intent) 或者 Activity.startActivity ForResult(int) 去运行一个Activity(可以在通过此方式启动后的Activity中调用 Activity.setResult() 设置结果参数,该参数将会在启动当前activity的activity中被接收---可以通过onActivityResult(int requestCode, int resultCode, Intent data) 接收)
传递一个Intent对象到 Context.startService(intent) 去启动一个service 或者 传递一个新的指令到正在运行的service中。另外,还可以通过 Context.bindService(intent) 去绑定一个Service。(在调用组件和目标Service 建立一个连接)
传递一个Intent对象到 任何一个broadcast methods (如: Context.sendBroadcast() , Context.sendOrderedBroadcast(), Context.sendStickyBroadcast() ) 该intent将被传递给所有已经被注册的broadcast receiver中。
在以上的三种情况下,当Intent被传递出后,Android系统会找到适合的activity,service,或者是多个broadcast receiver去响应这个intent。,这三种情况不会存在重叠的部分,它们相互独立,互不干扰。(调用Context.startActivity()后 intent只会被相应的activity接收到)
Activity的生命周期
Activity
android/frameworks/base/core/java/android/app/Activity.java  (源码位置)
一个Activity就是应用的一部分,提供与用户的交互界面,比如打电话,照相,发送邮件等。
创建一个Activity,必须继承onCreate()这个方法,然后在里面初始化主要的部件,然后在里面定义setContentView()去定义activity的用户界面。
有时候,你从一个activity跳转到另一个activity里,然后获取这个activity里的数据后再返回给上一个activity,就需要用到startActivityForResult()这个类,接收的结果在onActivityResult()这个类里。而普通的页面跳转就只要startActivity()即可。
Service
Android中的服务,它与Activity不同,它是不能与用户交互的,不能自己启动的,运行在后台的程序,如果我们退出应用时,Service进程并没有结束,它仍然在后台运行。
它一般用在一些需要后台运行的应用里,比如音乐播放器,手机流量监控,木马软件等。
当调用StartService时,先走oncreat方法,在走onstart方法。当stopservice时,走ondestory方法。
当绑定一个Service时,用bindService方法,这时先走oncreate方法,在走onbind方法。当想停止Service时,用onunbindService方法,这时先走onUnbind方法,在走ondestory方法。
Service范例
   public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        System.out.println("onBind");
        return null;
    }
  public void onCreate() {
        // TODO Auto-generated method stub
        System.out.println("onCreate");
        super.onCreate();
    }
    public void onDestroy() {
        // TODO Auto-generated method stub
        System.out.println("onDestroy");
        super.onDestroy();
    }
   public boolean onUnbind(Intent intent) {
        // TODO Auto-generated method stub
        System.out.println("onUnbind");
        return super.onUnbind(intent);
    }
Service范例
<service android:name=".TestService">  <intent-filter>   <action  android:name="com.android.testservice"/>  </intent-filter> </service>
当调用startService方法的时候,打印出来的log是:
  oncreate
  onstart
当调用stopService方法的时候,打印出来的log是:
  ondestory
当调用bindService和unbindServide方法时,打印出来的log是:
onCreate onBind onUnbind onDestroy
Broadcast Receiver
在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制。BroadcastReceiver是对发送出来的 Broadcast进行过滤接受并响应的一类组件。
首先在需要发送信息的地方,把要发送的信息和用于过滤的信息(如Action、Category)装入一个Intent对象,然后通过调用 sendOrderBroadcast()或sendStickyBroadcast()方法,把 Intent对象以广播方式发送出去。
当Intent发送以后,所有已经注册的BroadcastReceiver会检查注册时的IntentFilter是否与发送的Intent相匹配,若匹配则就会调用BroadcastReceiver的onReceive()方法。所以当我们定义一个BroadcastReceiver的时候,都需要实现onReceive()方法。
Broadcast Receiver使用
注册BroadcastReceiver有两种方式:
静态注册:在AndroidManifest.xml中用标签生命注册,并在标签内用标签设置过滤器。
<receiver android:name="myRecevice">    //继承BroadcastReceiver,重写onReceiver方法
    <intent-filter>   
      <action android:name="com.dragon.net"></action> //使用过滤器,接收指定action广播
      </intent-filter>
  </receiver>
动态注册:
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(String);   //为BroadcastReceiver指定action,使之用于接收同action的广播
registerReceiver(BroadcastReceiver,intentFilter);
一般:在onStart中注册,onStop中取消unregisterReceiver
指定广播目标Action:Intent intent=new Intent(actionString);
并且可通过Intent携带消息 :intent.putExtra("msg", "hi,我通过广播发送消息了");
发送广播消息:Context.sendBroadcast(intent )
Broadcast Receiver使用
public BroadcastReceiver mEvtReceiver=new BroadcastReceiver() {
 @Override
 public void onReceive(Context context, Intent intent) {
 String action=intent.getAction();
  if (action.equals("android.intent.action.BOOT_COMPLETED")) {
  // Do something
  }
 }
};
Content Provider
Content Provider是专门用于数据存储的类,是Android平台处理存取数据操作的核心。针对不同的应用模块都有各自的Content provider总类,下边是用户经常接触到的几个典型Content Provider应用: Content Provider Name : Intended Data
Browser : Browser bookmarks, Browser history, etc.
CallLog : Missed calls, Call datails, etc.
Contacts : Contact details
MediaStore : Media files such as audio, Video and Images
Settings : Device Settings and Preferences
调用Content Provider资源的标准URI结构: <standard_prefix>://<authority>/<data_path>/<id>例如: 1) 取得浏览器所有“书签”信息: 2) 取得系统通讯录中的信息: (如果取得某一个特定通讯记录,在路径URI的末端指定一个ID号:
Content Provider的用法
在实际开发中,Content Provider有以下两种用法:
1)和应用在一个APK包里 这种情况下和应用在同一进程中。process name和uid都一样。 2)单独在一个APK包里。 这种情况下,如果在AndroidManifest.xml文件里声明了和某个进程同属一个进程,如:
ContentProvider之Uri
在Android中,为了使用数据集中管理模式,使用了ContentProvider来进行数据管理,在使用ContentProvider进行 数据交互时就需要用到URI。为了让客户端程序能够使用你的数据,你必须要定义一个公开的URI,它由一些固定格式的文字组成,可以分成下面几个部分:

一个标准的URI前缀,它用来指示Android必须从ContentProvider中挑出一个来处理这个URI。
authority
一个唯一的标识符,标示这个URI需要查找的ContentProvider是由哪个组织开发的,一般用跟java包命名规范相似的方式来署名这个 开发组织。如果是Android内置的provider,则这个authority可以省略掉,否则authority是必须的,Google建议使用用 户自定义的继承ContentProvider的类的全名来作为,这个ContentProvider所要处理的URI的authority
path(路径)
ContentProvider根据这个路径信息来判断要返回什么类型的数据,所以这个后缀路径可以自由定义,但是有一些条件限制:
如果一个ContentProvider能查询返回很多种不同类型的数据,URI后缀要设置不同类型的数据所对应不同的URI后缀如内置的 Contact ContentProvider就是用来处理名片夹,它可以返回很多种类型的数据:联系人、电话、联系方式等。所以对应这些不同类型的数据就有不同的 URI后缀匹配:

而且我们要为不同的数据类型设置不同的MIME类型,第一个MIME类型是:vnd.android.cursor.item/person第二个MIME类型是:vnd.android.cursor.item/phone。
同时ContentProvider不仅可以返回单条数据,也可能以目录的形式返回多条数据。以上面2个URI来说,后缀的结尾都是数字,这表示查询对应某条记录,所以返回的数据是单条的,而如果是查询目录的形式就要去掉后面的数字如:

上面就是目录形式,对应他们的MIME类型也不同,所以我们将单条的MIME类型中的item改为dir,所以MIME类型是:vnd.android.cursor.dir/phone和vnd.android.cursor.dir/person。
Intent
Intent是一种运行时绑定(run-time binding)机制,它能在程序运行的过程中连接两个不同的组件。通过Intent,你的程序可以向Android表达某种请求或者意愿,Android会根据意愿的内容选择适当的组件来完成请求。比如,有一个Activity希望打开网页浏览器查看某一网页的内容,那么这个Activity只需要发出WEB_SEARCH_ACTION请求给Android,Android会根据Intent的请求内容,查询各组件注册时声明的IntentFilter,找到网页浏览器Activity来浏览网页。
Intent对象抽象地描述了要执行的操作,其描述的基本内容可以分为组件名称、Action(动作)、Data(数据)、Category(类别)、Extra(附加信息)和Flag(标志位)6部分
Intent对象
(1) 组件名称是指Intent目标组件的名称。组件名称是一个ComponentName对象,这种对象名称是目标组件类名和目标组件所在应用程序的包名的组合。组件中包名不一定要和manifest文件中的包名完全匹配。组件名称是一个可选项。如果Intent消息中指明了目标组件的名称,这就是一个显式消息,Intent会传递给指明的组件。如果目标组件名称并没有指定,Android则通Intent内的其他信息和已注册的IntentFilter的比较来选择合适的目标组件。
(2) Action描述Intent所触发动作名字的字符串,对于Broadcast Intent来说,Action指被广播出去的动作。理论上Action可以为任何字符串,而与Android系统应用有关的Action字符串以静态字符串常量的形式定义在了Intent类中。
(3) Data描述Intent要操作的数据URI和数据类型。有的动作需要对相应的数据进行处理。
(4) Category是对被请求组件的额外描述信息。Android也在Intent类中定义了一组静态字符串常量表示Intent不同的类别
(5) 列出了常用的Category常量
CATEGORY_BROWSABLE 目标Activity能通过在网页浏览器中点击链接而激活(比如,点击浏览器中的图片链接)
CATEGORY_GADGET 表示目标Activity可以被内嵌到其他Activity当中
CATEGORY_HOME 目标Activity是HOME Activity,即手机开机启动后显示的Activity,或按下HOME键后显示的Activity
CATEGORY_LAUNCHER 表示目标Activity是应用程序中最优先被执行的Activity
CATEGORY_PREFERENCE 表示目标Activity是一个偏好设置的Activity
(6) Extra当我们使用Intent连接不同的组件时,有时需要在Intent中附加额外的信息,以便将数据传递给目标Activity。比如ACTION_TIMEZONE_CHANGED需要带有附加信息表示新的时区。Extra用键值对结构保存在Intent对象当中,Intent对象通过调用方法putExtras()和getExtras()来存储和获取Extra。Extra是以Bundle对象的形式来保存的,Bundle对象提供了一系列put和get方法来设置、提取相应键值信息。在Intent类中同样为Android系统应用的一些Action所附加信息的键值定义了静态的字符串常量。
(7) Flag是各种各样的标志,许多指示Android系统如何去启动一个活动(例如,活动应该属于那个任务)和启动之后如何对待它(例如,它是否属于最近的活动列表)。
Intent消息机制
Intent消息机制通常有二种,一个是显式Intent(Explicit Intent),另一个是隐式Intent(Implicit Intent)。
显式Intent--需要在Intent中明确指定目标组件,也就是在Intent中明确写明目标组件的名称(Component name),需要指定完整的包名和类名。因为对于本程序以外的其他应用程序,你很难知道它的组件名字,所以显式的Intent通常用于应用程序内部通信,更确切的说,显示Intent是用于应用程序内部启动组件,通常又是Activity或Service。还没有见用显式Intent来给BroadcastReceiver发送广播的。
隐式Intent--也就是不在Intent中指定目标组件,在Intent中不能含有目标的名字。系统是根据其他的信息,比如Data,Type和Category去寻找目标组件。
隐式Intent通常用于与应用程序外部的组件进行通信。应用程序级别的组件复用也主要是靠隐式Intent来完成的。而IntentFilter也是只有隐式Intent才用的着,显式Intent都是直接把Intent传递给目标组件,根本不会理会组件的IntentFilter。
显式Intent用法
显式Intent使用起来比较简单,只需要在Intent中指定目标组件的名字即可,也就是通过Intent的方法设置Component属性。如前所述,显式Intent通常用于应用程序内部启动Activity或Service。事实上,并不完全局限在应用程序内部,对于外部应用的Activity和Service,也可以用显式Intent来启动,但你必须知道它们的名字。
Intent i=new Intent(); 
// Select one of them
i.setComponent(new ComponentName(getApplication(), ViewStubDemoActivity.class));
i.setComponent(new ComponentName(getApplication(), ViewStubDemoActivity.class.getName()));
i.setComponent(new ComponentName(getApplication().getPackageName(), ViewStubDemoActivity.class.getName()));
i.setClass(getApplication(), ViewStubDemoActivity.class);
i.setClassName(getApplication(), ViewStubDemoActivity.class.getName());
i.setClassName(getApplication().getPackageName(), ViewStubDemoActivity.class.getName());
startActivity(i);
因为应用程序内部的组件类,都是可以访问到的,所以要尽可能少写字串常量,以减少拼写错误,如果一定要使用包名和类名,也要注意,类名必须是全称,也就是从包名开始,如“com.hilton.networks.WifiManagerActivity"。
但是对于外部应用程序的Activity,通常只能通过以下方法:
Intent i=new Intent();
// select one of them
i.setComponent(new ComponentName("com.hilton.networks", "com.hilton.networks.WifiManagerActivity"));
i.setClassName("com.hilton.networks", "com.hilton.networks.WifiManagerActivity");
startActivity(i);
首先,带有Context为参数的是不能够用的,因为通常你无法拿到其他应用程序的Context,你只能拿到你所在应用程序的Context,所以用你所在的应用程序的Context去启动外部的Activity肯定会报错的。其次,不参再像上面那样通过Class.getName()去指定类名,你为你无法导入外部的类,会有编译错误的。另外,千万要注意不要拼错,否则会有RuntimeException抛出的。
对于Service组件,也是一样,Intent的写法与Activity组件一致,但是对于BroadcastReceiver组件通常都用显式Intent。
隐式Intent用法
IntentFilter是用来解析隐式Intent(Implicit Intent)的,也就是说告诉系统你的组件(Activity, Service, BroadcastReceiver)能够处理哪些隐式的Intent。在使用的时候我们通常是这样子的:
  <receiver ...>
           <intent-filter>
              <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
              <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
              <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
              <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
           </intent-filter>
 <receiver ...>
在Manifest中使用IntentFilter时要注意以下三点:
1. 千万注意拼写错误,对于IntentFilter里面的Action和Data字串常量不要写错,因为这个在编译时是不会被检查,在运行时又不会抛出异常,如果你拼写错了,比如大小写拼错了,在编译时和运行时都不会有错误,但是你的程序却不能正常工作,你的程序无法收到相应的Intent。
2. 要注意Data字段除了上面讨论的之外,对于IntentFilter还有另外的一点需要注意,就是对于某些Action是需要加上Data字段信息,否则有可能接收不到。
         <intent-filter>
              <action android:name="android.intent.action.MEDIA_MOUNTED"/>
              <action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
              <action android:name="android.intent.action.MEDIA_SHARED"/>
              <action android:name="android.intent.action.MEDIA_REMOVED"/>
              <action android:name="android.intent.action.MEDIA_EJECT"/>
              <data android:scheme="file" />
           </intent-filter>
隐式Intent用法
除了DataScheme还有一个是MimeType,这个对于系统公共接口是必须加上的,比如Email要处理Intent.ACTION_SENTTO,就需要这样声明:
    <activity android:name="EmailComposer">
           <intent-filter>
              <action android:name="android.intent.action.SEND"/>
              <data android:mimeType="image/*" />
           </intent-filter>
   </activity>
3. 同时也要注意Category字段
如果没有对IntentFilter写正确的Category字段,也是收不到Intent。比如:
<manifest ...>
    <receiver ...>
            <intent-filter>
                <action android:name="com.hilton.controlpanel.action.BUTTON_ACTION" />
                <category android:name="com.hilton.controlpanel.category.SELF_MAINTAIN" />
            </intent-filter>
   </receiver>
</manifest>
如果把Category去掉,死活也接收不到Intent,当然这要取决于Intent是如何发出的,如果Intent发出时没有加Category,那就没有必须在IntentFilter加上Category。
总之,对于Intent,要保证发出和接收完全一致,否则系统就无法找到相应的匹配,程序也就无法接收Intent。
有关于DEFAULT category,也要注意,如果是针对Activity的Implicit Intent隐式Intent,如果在没有其他Category的情况下,一定要加上DEFAULT Category。因为系统会在Context.startActivity(Intent)和Context.startActivityForResult(
Intent)时给Intent加上DEFAULT category。而对于Context.sendBroadcast(Intent),Context.sendOrderedBroadcast(Intent),Contxt.sendStickyBroadcast(Intent)和Context.bindService(Intent)Context.startService(Intent)就不会加DEFAULT Category。
另外要注意,尽量把Action进行合并写进一个IntentFilter中。因为对于每个IntentFilter标签都会创建一个IntentFilter对象,所以如果写几个就会有几个对象在那,不但耗费资源而且在匹配的时候也会耗费更多的时间,因为在查询匹配的时候是要一个IntentFilter对象接着一个IntentFilter对象进行检查的。直到找到最佳匹配或是到所有的IntentFilter都检查完为止。
IntentFilter的匹配规则
1. 通过Action字段来匹配这个是Intent中比较基本的一个字段,也比较简单,就是一个字串,如果相等就匹配成功,否则证明还没找到目标。但要注意,如果IntentFilter没有指定Action,那么它不会匹配到任何的隐式Intent,它只能被显式的Intent匹配上。反过来,如果Intent自己没有指定Action,那么它能匹配上含有任何Action的IntentFilter,但不能匹配上没有指定Action的IntentFilter。对于Action,平时要注意拼写错误,因为在AndroidManifest文件中声明Action都是字串,并且在编译时不会做检查,运行时,如果Action拼错了导致匹配不上,要么是程序不能正常工作,要么会有异常抛出。
 
2. 通过Category字段来匹配对于Activity来讲,如果想处理隐式Intent,并且除了Intent.ACTION_MAIN以外,必须指定Category为DEFAULT,否则不会被匹配到。因为Context.startActivity()和Context.startActivityForResult()会自动加上DEFAULT Category。其他情况,Service和BroadcastReceiver则不会,对于Service和BroadcastReceiver,如果Intent中没有指定Category,那么在其IntentFilter中也不必指定。
 
3. 通过Data字段来匹配这个相对来讲比较复杂,通常Data包含uri, scheme(content, file, http)和type(mimeType)对于Intent来讲有二个方法:
 
Intent.setData(Uri); //一个Uri,Scheme包含在其中
Intent.setType(String); //指定MimeType,比如'image/jpeg', 'audio/mpeg'等
Intent.setDataAndType(Uri, String); //上面二个方法的简便调用方式,一起搞进去
对于IntentFilter来讲,需要设置的是Scheme和Type,Scheme是对Uri的限制,目标需要限制Scheme是因为Scheme能告诉目录能从哪里拿到Uri所指向的文件,Type是MimeType对类型的限制。
 
<intent-filter>
     <action android:name="android.intent.action.SEND" />
     <category android:name="android.intent.category.DEFAULT" />
     <data android:scheme="content" android:mimeType="image/*" />
</intent-filter>
IntentFilter的匹配规则
Data匹配时的规则一共有四条:
a.如果Intent没有指定Data相关的字段,只能匹配上没有指定Data的IntentFilter。也就是说如果一个Intent没有指定任何的Data(Uri和Type),它只能匹配到没有指定任何Data(Scheme和Type)的IntentFilter。
b.如果一个Intent只指定了Uri但是没有Type(并且Type也不能够从Uri中分析出)只能匹配到仅指定了相应Scheme且没有指定Type的IntentFilter。实际的例子有如果一个Intent是想要发邮件,或是打电话,它们的Intent是类似这样的:"mailto:someone@sb.com"和"tel:1234567"。换句话说,这些Uri本身就是数据,而不再是一个指向数据的地址。比如:Phone中的Dialer就有如下的IntentFilter:
<intent-filter>
    <action android:name="android.intent.action.CALL" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="tel" />
</intent-filter>
但是注意,对于想对数据进行操作的Intent,最好不要只指定Uri,而不指定类型。因为如果这样做通常会匹配到一大堆
c. 如果一个Intent只指定了Type,但是没有指定Uri,它只能匹配到只指定了相应Type且没有指定Scheme的IntentFitler
d. 如果一个Intent即有Uri又有Type,那么它会匹配上:1).Uri和Type都匹配的IntentFilter;2).首先Type要匹配,另外如果Intent的Uri是content:或file:,且IntentFilter没有指定Scheme的IntentFilter。因为对于Android来讲content和file这二种Scheme是系统最常见也是用的最多的,所以就当成缺省值来对待。
另外需要注意,Type,因为是MimeType,所以是允许使用通配符的,比如'image/*',能匹配上所有以'image'为开头的类型,也说是说能匹配上所有的图像。
IntentFilter的匹配规则
根据Data匹配的例子
假如系统中有四个Activity,A的IntentFilter是这样子的:
 
 <activity ...>
         <intent-filter>
             <action android:name="android.intent.action.SEND" />
             <category android:name="android.intent.category.DEFAULT" />
             <data android:scheme="content" android:mimeType="image/*" />
         </intent-filter>
</activity>
这表明A可以发送一切图片类型,并且内容必须是由ContentProvider提供的,也就是Uri必须是以"开头的
而另外一个Activity B是这样子声明的:
 
 <activity ...>
         <intent-filter>
             <action android:name="android.intent.action.SEND" />
             <category android:name="android.intent.category.DEFAULT" />
             <data android:scheme="file" android:mimeType="image/*" />
         </intent-filter>
</activity>
这表明B可以发送一切图片,但内容必须是单独的一个文件,也就是Uri必须是由"开头的
IntentFilter的匹配规则
还有一个C是这样子声明的:
<activity ...>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
lt;/activity>
这表明C只能接收那些没有指定任何Uri和Type的Action是SEND的Intent。
而D是这样子声明的:
 <activity ...>
         <intent-filter>
             <action android:name="android.intent.action.SEND" />
             <category android:name="android.intent.category.DEFAULT" />
             <data android:mimeType="image/*" />
         </intent-filter>
</activity>
这表明D可以发送一切图片,无论是数据库内的(content),还是单独的文件(file)。
如果一个Intent是这样写的:
 
Intent share=new Intent(Intent.ACTION_SEND);
startActivity(share);
那么它只能匹配C,因为C没有指定数据和类型,Action是SEND,根据规则a,它只能匹配Activity A。但如果给Intent加上额外的条件
 
share.setDataAndType(uri,"image/jpeg");
那么如果uri是数据库内容,它会匹配到A,如果它是一个文件,会匹配到B。但无论是content还是file都会匹配到D,因为它能处理以任何形式存储的图片。但始终不会匹配到C,因为C没有声明Data字段,所以不会匹配上。
IntentFilter的匹配规则
所以,通常想把组件作为系统公用接口时都是这样子来写:
<activity ...>
        <intent-filter>
            <!-- implement public actions such as View, Edit, Pick or Send -->
            <action android:name="android.intent.action.SEND" />
            <!-- never forget default category, otherwise your activity never receives intents -->
            <category android:name="android.intent.category.DEFAULT" />
            <!-- specify mimeType to constrain data type, receive data from both content provider and file -->
            <data android:mimeType="image/*" />
            <!-- specify scheme to constrain data source, if necessary -->
            <data android:shceme="http" />
        </intent-filter>
lt;/activity>
Intent和IntentFilter对于组件Activity来讲注意事项比较多,但是对于Service和BroadcastReceiver来说就没有那么多的注意事项了,因为对于Service和BroadcastReceiver通常都不用设置Category和Data。但也有例外,比如SD相关广播和应用程序安装相关广播。
要处理SD状态变化的IntentFilter:
<intent-filter>
      <action android:name="android.intent.action.MEDIA_MOUNTED"/>
      <action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
      <action android:name="android.intent.action.MEDIA_SHARED"/>
      <action android:name="android.intent.action.MEDIA_REMOVED"/>
      <action android:name="android.intent.action.MEDIA_EJECT"/>
      <category android:name="android.intent.category.DEFAULT" />       
      <data android:scheme="file" />
</intent-filter>
Intent使用范例
// 给移动客服10086拨打电话 Uri uri=Uri.parse("tel:10086");
Intent intent=new Intent(Intent.ACTION_DIAL, uri); startActivity(intent);
// 打开Google主页 Uri uri=Uri.parse(");
Intent intent=new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);
// 进入无线网络设置界面(其它可以举一反三)
Intent intent=new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); startActivityForResult(intent, 0);
//过滤器
<activity>
        <intent-filter>
 <action android:name=”android.intent.action.GET_CONTENT” />
 <category android:name=”android.intent.category.DEFAULT” />
 <data android:mimetype=”vnd.android.cursor.dir/phone” />
        </intent-filter>
</activity>
Gallery里的AndroidManifest.xml
<activity android:name="com.android.camera.ImageGallery"
                android:label="@string/gallery_label"
                android:configChanges="orientation|keyboardHidden"
                android:icon="@drawable/ic_launcher_gallery">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/image" />
            </intent-filter>
        <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.OPENABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="image/*" />
                <data android:mimeType="video/*" />
            </intent-filter>
</activity>
AndroidManifest.xml综述
AndroidManifest.xml是Android应用程序中最重要的文件之一。它是Android程序的全局配置文件,是每个 android程序中必须的文件。它位于我们开发的应用程序的根目录下,描述了package中的全局数据,包括package中暴露的组件 (activities, services, 等等),以及他们各自的实现类,各种能被处理的数据和启动位置等重要信息。 因此,该文件提供了Android系统所需要的关于该应用程序的必要信息,即在该应用程序的任何代码运行之前系统所必须拥有的信息。
它描述了应用程序组件:该应用程序由哪些activity,service,broadcast receiver和content provider组成。它指定了实现每个组件的类以及公开发布它们的能力(例如,它们能持有哪个Intent信息)。这些声明使Android系统知道这 儿有什么组件以及在什么条件下它们可以被载入。 它决定那些进程将容纳应用程序组件。 它声明了本应用程序必须拥有哪些许可,以便访问API的被保护部分,以及与其他应用程序交互。 它也声明了其他应用程序在和该应用程序交互时需要持有的许可。 它列出了Instrumentation类,可以在应用程序运行时提供简档和其他信息。这些声明仅当应用程序在开发和测试过程中被提供;它们将在应用程序正式发布之前被移除。 它声明了该应用程序所需的Android API的最小化水平。 它列出了该应用程序必须链接的库。
AndroidManifest.xml综述
<?xml version="1.0" encoding="utf-8"?> <manifest>  //根节点,描述了package中所有的内容     <uses-permission /> //请求你的package正常运作所需赋予的安全许可。一个manifest能包含零个或更多此元素     <permission />  //声明了安全许可来限制哪些程序能使用你的package中的组件和功能。一个manifest能包含零个或更多此元素     <instrumentation />  //声明了用来测试此package或其他package指令组件的代码。一个manifest能包含零个或更多此元素     <uses-sdk />  //指定当前应用程序兼容的最低sdk版本号     <application>  //包含package中application级别组件声明的根节点。此元素也可包含 application中全局和默认的属性,如标签,icon,主题,必要的权限,等等。一个manifest能包含零个或一个此元素(不允许多余一个)         <activity>  //用来与用户交互的主要工具。当用户打开一个应用程序的初始页面时一个activity,大部分被使用到的其他页面也由不同的activity所实现并声明在另外的activity标记中。             <intent-filter>  //声明了指定的一组组件支持的Intent值                 <action />                 <category />                 <data />                     <type/>                     <schema/>                     <authority/>                     <path/>             </intent-filter>             <meta-data />         </activity>         <service>  //Service是能在后台运行任意时间的组件             <intent-filter> . . . </intent-filter>             <meta-data/>         </service>         <receiver>   //IntentReceiver能使你的application获得数据的改变或者发生的操作,即使它当前不在运行             <intent-filter> . . . </intent-filter>             <meta-data />         </receiver>         <provider>  //ContentProvider是用来管理持久化数据并发布给其他应用程序使用的组件             <grant-uri-permission />             <meta-data />         </provider>         <uses-library />         <uses-configuration />       </application> </manifest>
 

相关PPT

android图片幻灯片PPT:这是android图片幻灯片PPT,包括了什么是Android,如何安装 Android SDK 和Eclipse 插件,开发第一个Android应用,Android应用程序架构,ContentUris类使用介绍,Intent(意图),Activity生命周期,服务--Service,应用等内容,欢迎点击下载。
android内核开发ppt:这是android内核开发ppt,包括了搭建环境,源码下载,源码编译,驱动移植,SDCARD制作等内容,欢迎点击下载。
Android的教程之云计算和-Android-软件堆栈ppt:这是Android的教程之云计算和-Android-软件堆栈ppt,包括了计算机4 个主要部分,Android教程之 架构,活动功能单元,目的功能单元,服务功能单元,安全模型单元,Android教程之开发环境,使用 Android SDK,开发人员资源,云计算的思考:展望未来等内容,欢迎点击下载。
《android系统框图ppt》是由用户Foooooooood于2017-10-15上传,属于仪器设备PPT。

分享给小伙伴们:
android系统框图ppt:如果本文侵犯了您的权利, 请联系本网立即做出处理,谢谢。
当前位置:儿童诗歌网 > 励志名句android系统框图ppt转载请注明出处。
下一篇:没有了
android系统框图ppt相关文章