`
George_ghc
  • 浏览: 95049 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
Android Intent大全更新到API Level8 http://dev.10086.cn/cmdn/wiki/index.php?edition-view-4677-1.html
 Android 1.5 API Level3
android.intent.action.ALL_APPS   
android.intent.action.ANSWER   
android.intent.action.ATTACH_DATA   
android.intent.action.BUG_REPORT   
android.intent.action.CALL   
android.intent.action.CALL_BUTTON   
android.intent.action.CHOOSER   
android.intent.action.CREATE_LIVE_FOLDER   
android.intent.action.CREATE_SHORTCUT   
android.intent.action.DELETE   
android.intent.action.DIAL   
android.intent.action.EDIT   
android.intent.action.GET_CONTENT   
android.intent.action.INSERT   
android.intent.action.INSERT_OR_EDIT   
android.intent.action.MAIN   
android.intent.action.MEDIA_SEARCH   
android.intent.action.PICK   
android.intent.action.PICK_ACTIVITY   
android.intent.action.RINGTONE_PICKER   
android.intent.action.RUN   
android.intent.action.SEARCH   
android.intent.action.SEARCH_LONG_PRESS   
android.intent.action.SEND   
android.intent.action.SENDTO   
android.intent.action.SET_WALLPAPER   
android.intent.action.SYNC   
android.intent.action.SYSTEM_TUTORIAL   
android.intent.action.VIEW   
android.intent.action.VOICE_COMMAND   
android.intent.action.WEB_SEARCH   
android.net.wifi.PICK_WIFI_NETWORK   
android.settings.AIRPLANE_MODE_SETTINGS   
android.settings.APN_SETTINGS   
android.settings.APPLICATION_DEVELOPMENT_SETTINGS   
android.settings.APPLICATION_SETTINGS   
android.settings.BLUETOOTH_SETTINGS   
android.settings.DATA_ROAMING_SETTINGS   
android.settings.DATE_SETTINGS   
android.settings.DISPLAY_SETTINGS   
android.settings.INPUT_METHOD_SETTINGS   
android.settings.INTERNAL_STORAGE_SETTINGS   
android.settings.LOCALE_SETTINGS   
android.settings.LOCATION_SOURCE_SETTINGS   
android.settings.MANAGE_APPLICATIONS_SETTINGS   
android.settings.MEMORY_CARD_SETTINGS   
android.settings.NETWORK_OPERATOR_SETTINGS   
android.settings.QUICK_LAUNCH_SETTINGS   
android.settings.SECURITY_SETTINGS   
android.settings.SETTINGS   
android.settings.SOUND_SETTINGS   
android.settings.SYNC_SETTINGS   
android.settings.USER_DICTIONARY_SETTINGS   
android.settings.WIFI_IP_SETTINGS   
android.settings.WIFI_SETTINGS   
android.settings.WIRELESS_SETTINGS  
android.bluetooth.a2dp.intent.action.SINK_STATE_CHANGED   
android.bluetooth.intent.action.BLUETOOTH_STATE_CHANGED   
android.bluetooth.intent.action.BOND_STATE_CHANGED_ACTION   
android.bluetooth.intent.action.DISCOVERY_COMPLETED   
android.bluetooth.intent.action.DISCOVERY_STARTED   
android.bluetooth.intent.action.HEADSET_ADUIO_STATE_CHANGED   
android.bluetooth.intent.action.HEADSET_STATE_CHANGED   
android.bluetooth.intent.action.NAME_CHANGED   
android.bluetooth.intent.action.PAIRING_CANCEL   
android.bluetooth.intent.action.PAIRING_REQUEST   
android.bluetooth.intent.action.REMOTE_DEVICE_CONNECTED   
android.bluetooth.intent.action.REMOTE_DEVICE_DISAPPEARED   
android.bluetooth.intent.action.REMOTE_DEVICE_DISAPPEARED   
android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECTED   
android.bluetooth.intent.action.REMOTE_DEVICE_DISCONNECT_REQUESTED   
android.bluetooth.intent.action.REMOTE_DEVICE_FOUND   
android.bluetooth.intent.action.REMOTE_NAME_FAILED   
android.bluetooth.intent.action.REMOTE_NAME_UPDATED   
android.bluetooth.intent.action.SCAN_MODE_CHANGED   
android.intent.action.AIRPLANE_MODE   
android.intent.action.BATTERY_CHANGED   
android.intent.action.BATTERY_LOW   
android.intent.action.BOOT_COMPLETED   
android.intent.action.CAMERA_BUTTON   
android.intent.action.CONFIGURATION_CHANGED   
android.intent.action.DATA_SMS_RECEIVED   
android.intent.action.DATE_CHANGED   
android.intent.action.DEVICE_STORAGE_LOW   
android.intent.action.DEVICE_STORAGE_OK   
android.intent.action.GTALK_CONNECTED   
android.intent.action.GTALK_DISCONNECTED   
android.intent.action.HEADSET_PLUG   
android.intent.action.INPUT_METHOD_CHANGED   
android.intent.action.MANAGE_PACKAGE_STORAGE   
android.intent.action.MEDIA_BAD_REMOVAL   
android.intent.action.MEDIA_BUTTON   
android.intent.action.MEDIA_CHECKING   
android.intent.action.MEDIA_EJECT   
android.intent.action.MEDIA_MOUNTED   
android.intent.action.MEDIA_NOFS   
android.intent.action.MEDIA_REMOVED   
android.intent.action.MEDIA_SCANNER_FINISHED   
android.intent.action.MEDIA_SCANNER_SCAN_FILE   
android.intent.action.MEDIA_SCANNER_STARTED   
android.intent.action.MEDIA_SHARED   
android.intent.action.MEDIA_UNMOUNTABLE   
android.intent.action.MEDIA_UNMOUNTED   
android.intent.action.NEW_OUTGOING_CALL   
android.intent.action.PACKAGE_ADDED   
android.intent.action.PACKAGE_CHANGED   
android.intent.action.PACKAGE_DATA_CLEARED   
android.intent.action.PACKAGE_INSTALL   
android.intent.action.PACKAGE_REMOVED   
android.intent.action.PACKAGE_REPLACED   
android.intent.action.PACKAGE_RESTARTED   
android.intent.action.PHONE_STATE   
android.intent.action.PROVIDER_CHANGED   
android.intent.action.REBOOT   
android.intent.action.SCREEN_OFF   
android.intent.action.SCREEN_ON   
android.intent.action.TIMEZONE_CHANGED   
android.intent.action.TIME_SET   
android.intent.action.TIME_TICK   
android.intent.action.UID_REMOVED   
android.intent.action.UMS_CONNECTED   
android.intent.action.UMS_DISCONNECTED   
android.intent.action.USER_PRESENT   
android.intent.action.WALLPAPER_CHANGED   
android.media.AUDIO_BECOMING_NOISY   
android.media.RINGER_MODE_CHANGED   
android.media.VIBRATE_SETTING_CHANGED   
android.net.conn.BACKGROUND_DATA_SETTING_CHANGED   
android.net.wifi.NETWORK_IDS_CHANGED   
android.net.wifi.RSSI_CHANGED   
android.net.wifi.SCAN_RESULTS   
android.net.wifi.STATE_CHANGE   
android.net.wifi.WIFI_STATE_CHANGED   
android.net.wifi.supplicant.CONNECTION_CHANGE   
android.net.wifi.supplicant.STATE_CHANGE   
android.provider.Telephony.SIM_FULL   
android.provider.Telephony.SMS_RECEIVED   
android.provider.Telephony.WAP_PUSH_RECEIVED   
com.google.gservices.intent.action.GSERVICES_CHANGED  
Android 1.6 API Level4
android.intent.action.POWER_USAGE_SUMMARY   
android.intent.action.SEND_MULTIPLE   
android.speech.tts.engine.CHECK_TTS_DATA   
android.speech.tts.engine.INSTALL_TTS_DATA
android.intent.action.ACTION_POWER_CONNECTED   
android.intent.action.ACTION_POWER_DISCONNECTED   
android.intent.action.ACTION_SHUTDOWN   
android.intent.action.BATTERY_OKAY   
android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED   
android.speech.tts.engine.TTS_DATA_INSTALLED   
com.android123.action.CWJ_DEMO
com.google.gservices.intent.action.GSERVICES_OVERRIDE
Android 2.0,2..01,2.1 API Level5,6,7
android.bluetooth.adapter.action.REQUEST_DISCOVERABLE   
android.bluetooth.adapter.action.REQUEST_ENABLE   
android.settings.ACCESSIBILITY_SETTINGS   
android.settings.PRIVACY_SETTINGS
android.bluetooth.a2dp.action.SINK_STATE_CHANGED   
android.bluetooth.adapter.action.DISCOVERY_FINISHED   
android.bluetooth.adapter.action.DISCOVERY_STARTED   
android.bluetooth.adapter.action.LOCAL_NAME_CHANGED   
android.bluetooth.adapter.action.SCAN_MODE_CHANGED   
android.bluetooth.adapter.action.STATE_CHANGED   
android.bluetooth.device.action.ACL_CONNECTED   
android.bluetooth.device.action.ACL_DISCONNECTED   
android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED   
android.bluetooth.device.action.BOND_STATE_CHANGED   
android.bluetooth.device.action.CLASS_CHANGED   
android.bluetooth.device.action.FOUND   
android.bluetooth.device.action.NAME_CHANGED   
android.bluetooth.devicepicker.action.DEVICE_SELECTED   
android.bluetooth.devicepicker.action.LAUNCH   
android.bluetooth.headset.action.AUDIO_STATE_CHANGED   
android.bluetooth.headset.action.STATE_CHANGED
android.intent.action.DOCK_EVENT   
android.provider.Telephony.SMS_REJECTED
android.intent.action.LOCALE_CHANGED
Android 2.2 API Level8
android.app.action.ADD_DEVICE_ADMIN   
android.app.action.SET_NEW_PASSWORD   
android.intent.action.MUSIC_PLAYER   
android.search.action.SEARCH_SETTINGS   
android.settings.ADD_ACCOUNT_SETTINGS   
android.settings.DEVICE_INFO_SETTINGS 
android.app.action.ACTION_PASSWORD_CHANGED   
android.app.action.ACTION_PASSWORD_FAILED   
android.app.action.ACTION_PASSWORD_SUCCEEDED   
android.app.action.DEVICE_ADMIN_DISABLED   
android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED   
android.app.action.DEVICE_ADMIN_ENABLED   
android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE   
android.intent.action.EXTERNAL_APPLICATIONS_UNAVAILABLE   
android.media.SCO_AUDIO_STATE_CHANGED 
Android中的Intent详细讲解
在一个Android应用中,主要是由四种组件组成的,这四种组件可参考“Android应用的构成”。
而这四种组件是独立的,它们之间可以互相调用,协调工作,最终组成一个真正的Android应用。

在这些组件之间的通讯中,主要是由Intent协助完成的。
Intent负责对应用中一次操作的动作、动作涉及数据、附加数据进行描述,Android则根据此Intent的描述,负责找到对应的组件,将 Intent传递给调用的组件,并完成组件的调用。
因此,Intent在这里起着一个媒体中介的作用,专门提供组件互相调用的相关信息,实现调用者与被调用者之间的解耦。
例如,在一个联系人维护的应用中,当我们在一个联系人列表屏幕(假设对应的Activity为listActivity)上,点击某个联系人后,希望能够跳出此联系人的详细信息屏幕(假设对应的Activity为detailActivity)
为了实现这个目的,listActivity需要构造一个 Intent,这个Intent用于告诉系统,我们要做“查看”动作,此动作对应的查看对象是“某联系人”,然后调用startActivity (Intent intent),
将构造的Intent传入,系统会根据此Intent中的描述,到ManiFest中找到满足此Intent要求的Activity,系统会调用找到的 Activity,即为detailActivity,最终传入Intent,detailActivity则会根据此Intent中的描述,执行相应的操作。

一、抽象描述要描述什么

在Android参考文档中,对Intent的定义是执行某操作的一个抽象描述(确实很抽象)。我们先来看看这里的抽象描述,到底描述了什么。
首先,是要执行的动作(action)的一个简要描述,如VIEW_ACTION(查看)、EDIT_ACTION(修改)等,Android为我们定义了一套标准动作:

MAIN_ACTION
VIEW_ACTION
EDIT_ACTION
PICK_ACTION
GET_CONTENT_ACTION
DIAL_ACTION
CALL_ACTION
SENDTO_ACTION
ANSWER_ACTION
INSERT_ACTION
DELETE_ACTION
RUN_ACTION
LOGIN_ACTION
CLEAR_CREDENTIALS_ACTION
SYNC_ACTION
PICK_ACTIVITY_ACTION
WEB_SEARCH_ACTION
此外,我们还可以根据应用的需要,定义我们自己的动作,并可定义相应的Activity来处理我们的自定义动作。

其次,是执行动作要操作的数据(data),Android中采用指向数据的一个URI来表示,如在联系人应用中,一个指向某联系人的URI可能为:content://contacts/1。
这种URI表示,通过 ContentURI这个类来描述,具体可以参考android.net.ContentURI类的文档。

以联系人应用为例,以下是一些action / data对,及其它们要表达的意图:
VIEW_ACTION content://contacts/1-- 显示标识符为"1"的联系人的详细信息
EDIT_ACTION content://contacts/1-- 编辑标识符为"1"的联系人的详细信息
VIEW_ACTION content://contacts/-- 显示所有联系人的列表
PICK_ACTION content://contacts/-- 显示所有联系人的列表,并且允许用户在列表中选择一个联系人,然后把这个联系人返回给父activity。例如:电子邮件客户端可以使用这个Intent,要求用户在联系人列表中选择一个联系人

另外,除了action和data这两个重要属性外,还有一些附加属性: 
category(类别),被执行动作的附加信息。例如 LAUNCHER_CATEGORY 表示Intent 的接受者应该在Launcher中作为顶级应用出现;而ALTERNATIVE_CATEGORY表示当前的Intent是一系列的可选动作中的一个,这些动作可以在同一块数据上执行。
type(数据类型),显式指定Intent的数据类型(MIME)。一般Intent的数据类型能够根据数据本身进行判定,但是通过设置这个属性,可以强制采用显式指定的类型而不再进行推导。
component(组件),指定Intent的的目标组件的类名称。通常 Android会根据Intent 中包含的其它属性的信息,比如action、data/type、category进行查找,最终找到一个与之匹配的目标组件。但是,如果 component这个属性有指定的话,将直接使用它指定的组件,而不再执行上述查找过程。指定了这个属性以后,Intent的其它所有属性都是可选的。
extras(附加信息),是其它所有附加信息的集合。使用extras可以为组件提供扩展信息,比如,如果要执行“发送电子邮件”这个动作,可以将电子邮件的标题、正文等保存在extras里,传给电子邮件发送组件。

总之,action、 data/type、category和extras 一起形成了一种语言。
这种语言使系统能够理解诸如“查看某联系人的详细信息”之类的短语。
随着应用不断的加入到系统中,它们可以添加新的action、 data/type、category来扩展这种语言。
应用也可以提供自己的Activity来处理已经存在的这样的“短语”,从而改变这些“短语”的行为。

二、Android如何解析Intent

在应用中,我们可以以两种形式来使用Intent:
直接Intent:指定了component属性的Intent(调用setComponent(ComponentName)或者setClass(Context, Class)来指定)。通过指定具体的组件类,通知应用启动对应的组件。
间接Intent:没有指定comonent属性的Intent。这些Intent需要包含足够的信息,这样系统才能根据这些信息,在在所有的可用组件中,确定满足此Intent的组件。
对于直接Intent,Android不需要去做解析,因为目标组件已经很明确,Android需要解析的是那些间接Intent,通过解析,将 Intent映射给可以处理此Intent的Activity、IntentReceiver或Service。
Intent解析机制主要是通过查找已注册在AndroidManifest.xml中的所有IntentFilter及其中定义的Intent,最终找到匹配的Intent。在这个解析过程中,Android是通过Intent的action、type、category这三个属性来进行判断的,判断方法如下:
如果Intent指明定了action,则目标组件的IntentFilter的action列表中就必须包含有这个action,否则不能匹配;
如果Intent没有提供type,系统将从data中得到数据类型。和action一样,目标组件的数据类型列表中必须包含Intent的数据类型,否则不能匹配。
如果Intent中的数据不是content: 类型的URI,而且Intent也没有明确指定它的type,将根据Intent中数据的scheme (比如 http: 或者mailto: ) 进行匹配。同上,Intent 的scheme必须出现在目标组件的scheme列表中。
如果Intent指定了一个或多个category,这些类别必须全部出现在组建的类别列表中。比如Intent中包含了两个类别:LAUNCHER_CATEGORY 和 ALTERNATIVE_CATEGORY,解析得到的目标组件必须至少包含这两个类别。

三、应用例子

以下,以Android SDK中的便笺例子来说明,Intent如何定义及如何被解析。这个应用可以让用户浏览便笺列表、查看每一个便笺的详细信息。 



<manifest 
xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.google.android.notepad"> 
<application 
android:icon="@drawable/app_notes" 
android:label="@string/app_name"> 

<provider 
class="NotePadProvider" 
android:authorities="com.google.provider.NotePad" 
/> 

<activity 
class=".NotesList" 
android:label="@string/title_notes_list"> 
     <intent-filter> 
       <action android:value="android.intent.action.MAIN"/> 
       <category android:value="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     <intent-filter> 
       <action android:value="android.intent.action.VIEW"/> 
       <action android:value="android.intent.action.EDIT"/> 
       <action android:value="android.intent.action.PICK"/> 
       <category android:value="android.intent.category.DEFAULT"/> 
       <type android:value="vnd.android.cursor.dir/vnd.google.note"/> 
      </intent-filter> 
     <intent-filter> 
       <action android:value="android.intent.action.GET_CONTENT"/> 
       <category android:value="android.intent.category.DEFAULT"/> 
       <type android:value="vnd.android.cursor.item/vnd.google.note"/> 
      </intent-filter> 
    </activity> 


  <activity class=".NoteEditor" android:label="@string/title_note"> 
     <intent-filter android:label="@string/resolve_edit"> 
       <action android:value="android.intent.action.VIEW"/> 
       <action android:value="android.intent.action.EDIT"/> 
       <category android:value="android.intent.category.DEFAULT"/> 
       <type android:value="vnd.android.cursor.item/vnd.google.note"/> 
      </intent-filter> 
     <intent-filter> 
       <action android:value="android.intent.action.INSERT"/> 
       <category android:value="android.intent.category.DEFAULT"/> 
       <type android:value="vnd.android.cursor.dir/vnd.google.note"/> 
      </intent-filter> 
    </activity> 


  <activity class=".TitleEditor" android:label="@string/title_edit_title" android:theme="@android:style/Theme.Dialog"> 
     <intent-filter android:label="@string/resolve_title"> 
       <action android:value="com.google.android.notepad.action.EDIT_TITLE"/> 
       <category android:value="android.intent.category.DEFAULT"/> 
       <category android:value="android.intent.category.ALTERNATIVE"/> 
       <category android:value="android.intent.category.SELECTED_ALTERNATIVE"/> 
       <type android:value="vnd.android.cursor.item/vnd.google.note"/> 
      </intent-filter> 
    </activity> 
</application> 
</manifest>

复制代码
例子中的第一个Activity是com.google.android.notepad.NotesList,它是应用的主入口,提供了三个功能,分别由三个 intent-filter进行描述:

1、第一个是进入便笺应用的顶级入口(action为android.app.action.MAIN)。类型为android.app.category.LAUNCHER表明这个Activity将在Launcher中列出。
2、第二个是,当type为vnd.android.cursor.dir/vnd.google.note(保存便笺记录的目录)时,可以查看可用的便笺(action为android.app.action.VIEW),或者让用户选择一个便笺并返回给调用者(action为 android.app.action.PICK)。
3、第三个是,当type为vnd.android.cursor.item/vnd.google.note时,返回给调用者一个用户选择的便笺(action为android.app.action.GET_CONTENT),而用户却不需要知道便笺从哪里读取的。有了这些功能,下面的 Intent就会被解析到NotesList这个activity:

{ action=android.app.action.MAIN }:与此Intent匹配的Activity,将会被当作进入应用的顶级入口。
{ action=android.app.action.MAIN, category=android.app.category.LAUNCHER }:这是目前Launcher实际使用的 Intent,用于生成Launcher的顶级列表。
{ action=android.app.action.VIEW data=content://com.google.provider.NotePad/notes }:
显示"content://com.google.provider.NotePad/notes"下的所有便笺的列表,使用者可以遍历列表,并且察看某便笺的详细信息。
{ action=android.app.action.PICK data=content://com.google.provider.NotePad/notes }:
显示"content://com.google.provider.NotePad/notes"下的便笺列表,让用户可以在列表中选择一个,然后将选择的便笺的 URL返回给调用者。
{ action=android.app.action.GET_CONTENT type=vnd.android.cursor.item/vnd.google.note }:和上面的action为pick的Intent类似,不同的是这个Intent允许调用者(在这里指要调用NotesList的某个 Activity)指定它们需要返回的数据类型,系统会根据这个数据类型查找合适的 Activity(在这里系统会找到NotesList这个Activity),供用户选择便笺。
第二个Activity是com.google.android.notepad.NoteEditor,它为用户显示一条便笺,并且允许 用户修改这个便笺。
它定义了两个intent-filter,所以具有两个功能。

第一个功能是,当数据类型为 vnd.android.cursor.item/vnd.google.note时,允许用户查看和修改一个便签(action为 android.app.action.VIEW和android.app.action.EDIT)。
第二个功能是,当数据类型为 vnd.android.cursor.dir/vnd.google.note,为调用者显示一个新建便笺的界面,并将新建的便笺插入到便笺列表中(action为android.app.action.INSERT)。
      有了这两个功能,下面的Intent就会被解析到NoteEditor这个activity:

{ action=android.app.action.VIEW data=content://com.google.provider.NotePad/notes/{ID}} :向用户显示标识为 ID的便笺。

{ action=android.app.action.EDIT data=content://com.google.provider.NotePad/notes/{ID}}:允许用户编辑标识为ID的便笺。

{ action=android.app.action.INSERT data=content://com.google.provider.NotePad/notes }:在“content://com.google.provider.NotePad/notes”这个便笺列表中创建一个新的空便笺,并允许用户编辑这个便签。当用户保存这个便笺后,这个新便笺的URI将会返回给调用者。
最后一个Activity是com.google.android.notepad.TitleEditor,它允许用户编辑便笺的标题。

它可以被实现为一个应用可以直接调用(在Intent中明确设置component属性)的类,不过这里我们将为你提供一个在现有的数据上发布可选操作的方法。

在这个 Activity的唯一的intent-filter中,拥有一个私有的action: com.google.android.notepad.action.EDIT_TITLE,表明允许用户编辑便笺的标题。

和前面的view和edit 动作一样,调用这个Intent 的时候,也必须指定具体的便笺(type为vnd.android.cursor.item/vnd.google.note)。不同的是,这里显示和编辑的只是便笺数据中的标题。

      除了支持缺省类别(android.intent.category.DEFAULT),标题编辑器还支持另外两个标准类别: android.intent.category.ALTERNATIVE和
android.intent.category.SELECTED_ALTERNATIVE。

实现了这两个类别之后,其它 Activity就可以调用queryIntentActivityOptions(ComponentName, Intent[], Intent, int)查询这个Activity提供的action,而不需要了解它的具体实现;

或者调用addIntentOptions(int, int, ComponentName, Intent[], Intent, int, Menu.Item[])建立动态菜单。需要说明的是,在这个intent-filter中有一个明确的名称(通过android:label= "@string/resolve_title"指定),在用户浏览数据的时候,如果这个Activity是数据的一个可选操作,指定明确的名称可以为用户提供一个更好控制界面。

有了这个功能,下面的Intent就会被解析到TitleEditor这个Activity:

{ action=com.google.android.notepad.action.EDIT_TITLE data=content://com.google.provider.NotePad/notes/{ID}}:显示并且允许用户编辑标识为ID的便笺的标题
代码降级 (解决JDK1.5的代码在转到1.4下无法运行)
一. 需要转换的内容为WEB-INF下的lib和classes 

二. 转换所用的工具为retrotranslator transformer 

三. 具体转换步骤: 
  1.先建立一个用于转换的目录,将retrotranslator transformer解压到目录中 

  2.将report_web中的lib和classes拷贝到目录中,另外建立lib14和classes14用于放置转换完成的文件 

  3.开始转换lib:(lib的转换为一次转换一个jar包) 

    a)新建一个批处理命令trans.bat,内容为java -jar transformer.jar -srcjar lib\%1 -destjar lib14\%1 

    b)在转换目录下执行trans+空格+需转换的jar包名.jar 

    c)需确保lib和lib14目录存在且转换的jar包名正确 

    d)全部转换结束后,lib14下即为转换后的lib,覆盖到report_web相关lib目录下即可 

  4.开始转换classes:(classes的转换为一个目录一次性转换) 

    a)在转换目录下执行java -jar transformer.jar -srcdir classes -destdir classes14 

    b)需确保classes和classes14目录存在 

    c)转换完成后将classes14中的内容拷贝到report_web下的classes中即可 

  5.至此所有转换工作结束 

  6.转换后的report_web即可在jdk1.4环境下运行 

备注: 

3.如果新增了lib包则需要转换lib jar包,如果变更了程序内容则需要转换相关class文件
Android 自定义FastScroller
设置快速滚动属性很容易,只需在布局的xml文件里设置属性即可:

        但是有时候会发现设置属性无效,滚动ListView并未出现滑块。原因是该属性生效有最小记录限制。当ListView记录能够在4屏以内显示(也就是说滚动4页)就不会出现滑块。可能是api设计者认为这么少的记录不需要快速滚动。

        我的依据是android源代码,见FastScroller的常量声明:
[code="Java"]

// 最小的数字显示页面来证明快速卷轴
private static int MIN_PAGES = 4;
// 有足够的页面需要非常快速滚动吗?只有当总数变化接器会重新计算
if (mItemCount != totalItemCount && visibleItemCount > 0) {
mItemCount = totalItemCount;
mLongList = mItemCount / visibleItemCount >= MIN_PAGES;
}
[/code]
通篇查看了ListView及其超累AbsListView,都未找到自定义图片的设置接口。看来是没打算让开发者更改了。但是用户要求我们自定义这个图片。那只能用非常手段了。

        经过分析发现,该图片是ListView超类AbsListView的一个成员mFastScroller对象的成员 mThumbDrawable。这里mThumbDrawable是Drawable类型的。mFastScroller是FastScroller类型,这个类型比较麻烦,类的声明没有modifier,也就是default(package),只能供包内的类调用。

       因此反射代码写的稍微麻烦一些:
[code="Java"]
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
f.setAccessible(true);
Object o=f.get(listView);
f=f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable=(Drawable) f.get(o);
drawable=getResources().getDrawable(R.drawable.icon);
f.set(o,drawable);
Toast.makeText(this, f.getType().getName(), 1000).show();
} catch (Exception e) {
throw new RuntimeException(e);
}
[/code]
这样我们就做完了,我们就可以改变默认的滑块图片了。
Android中自定义Activity和Dialog的位置大小背景和透明度等 控件属性
1.自定义Activity显示样式

先在res/values下建colors.xml文件,写入:
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <!-- 设置透明度为56%(9/16)左右 -->  
    <color name="transparent">#9000</color>       
</resources> 
[/code]
这个值设定了整个界面的透明度,为了看得见效果,现在设为透明度为56%(9/16)左右。

再在res/values/下建styles.xml,设置程序的风格
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>    
<resources>  
    <style name="Transparent">
        <!--设置背景 -->     
        <item name="android:windowBackground">@color/transparent</item>  
        <!-- 设置底层可见 -->     
        <item name="android:windowIsTranslucent">true</item>  
        <!-- 设置跳转效果 -->  
        <item name="android:windowAnimationStyle">@+android:style/Animation.Translucent</item>
    </style>   
</resources>  
[/code]

最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意<activity>标签中添加 
android:theme = "@style/transparent" 
如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。 
最后运行程序,哈哈,是不是发现整个界面都被蒙上一层半透明了。最后可以把背景色#9000换成#0000,运行程序后,就全透明了,看得见背景下的所有东西可以却都操作无效。呵呵.... 
2.将Activity以Dialog的形式显示并自定义样式

先在res/drawable下建bgconfig.xml文件,写入:
[code="xml"]
<?xml version="1.0" encoding="utf-8"?>    
<shape xmlns:android="http://schemas.android.com/apk/res/android">    
    <solid android:color="#ffffff" />    
    <stroke android:width="3dp" color="#000000" />    
    <corners android:radius="3dp" />    
    <padding android:left="3dp" android:top="3dp" android:right="3dp"    
        android:bottom="3dp" />  
</shape>   
[/code]
再在res/values/下建styles.xml,设置程序的风格
<?xml version="1.0" encoding="utf-8"?>    
<resources>  
        <!-- 设置样式 -->  
    <style name="Theme.MyActivity" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@drawable/bgconfig</item>  
    </style>  
</resources>  
最后一步,把这个styles.xml用在相应的Activity上。即在AndroidManifest.xml中的任意<activity>标签中添加 
android:theme = "@style/transparent" 
如果想设置所有的activity都使用这个风格,可以把这句标签语句添加在<application>中。
3.设置窗口大小和位置
WindowManager m = getWindowManager();    
Display d = m.getDefaultDisplay();  //为获取屏幕宽、高    
           
LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值    
p.height = (int) (d.getHeight() * 1.0);   //高度设置为屏幕的1.0   
p.width = (int) (d.getWidth() * 0.7);    //宽度设置为屏幕的0.8   
p.alpha = 1.0f;      //设置本身透明度  
p.dimAmount = 0.0f;      //设置黑暗度  
           
getWindow().setAttributes(p);     //设置生效  
getWindow().setGravity(Gravity.RIGHT);       //设置靠右对齐  

定时器Timer 和 handler
虽然Timer和handler的任务执行代码都放在run方法中,但Timer是在线程中执行run方法的,而handler将执行的动作添加到Android系统的消息队列中。因此,使用Timer执行run方法时,在run方法中不能直接更新GUI组件。
计时器 Chronometer
package com.ghc.mobile.aidl;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Chronometer;
import android.widget.TextView;
import android.widget.Chronometer.OnChronometerTickListener;

public class ChronometerActicity extends Activity implements OnClickListener,OnChronometerTickListener{
	private Chronometer chronometer;
	private TextView tvTime;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		tvTime = (TextView)findViewById(R.id.tvTime);
		chronometer = (Chronometer)findViewById(R.id.chronometer);
		//设置记时监听事件
		chronometer.setOnChronometerTickListener(this);
		//设置计时信息的格式
		chronometer.setFormat("计时器:%s");
	}
	@Override
	protected void onPause() {
		super.onPause();
	}
	@Override
	protected void onResume() {
		super.onResume();
	}
	public void onClick(View view) {
		switch(view.getId()) {
		case R.id.btnStart:
			//开始计时器
			chronometer.start();
			break;
		case R.id.btnStop:
			//停止计时器
			chronometer.stop();
			break;
		case R.id.btnReset:
			//重置计时器
			chronometer.setBase(SystemClock.elapsedRealtime());
			break;
		}
	}
	//1s调用一次
	public void onChronometerTick(Chronometer arg0) {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		//将当前时间显示在TextView组件中
		tvTime.setText("当前时间:" + sdf.format(new Date()));
	}

}
获取黏贴板(clipboardManager)对象
//获得ClipboardManager对象
	android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
	clipboardManager.setText("设置黏贴板中的内容");
启动service时启动activity
public class StartupReceiver extends BroadcastReceiver
{
   @Override
   public void onReceive(Context context,Intent intent)
   {
       //启动一个Service
       Intent serviceIntent = new Intent(context,MyService.class);
       context.startService(serviceIntent);
       Intent activityIntent = new Intent(context,MessageActivity.class);
       //要想在Service中启动Activity,必须设置如下标志
        activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       context.startActivity(activityIntent);
   }
}
AndroidManifest文件中代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.ghc.mobile.aidl"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
	<uses-permission android:name="android.permission.RECEIVER_BOOT_COMPLETED"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MessageActivity" android:theme="@andrid:style/Theme.Dialog">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
	<receiver android:name="StartupReceiver">
		<intent-filter>
			<action android:name="android.intent.action.BOOT_COMPLETED"/>
			<category android:name="android.intent.category.LAUNCHER"/>
		</intent-filter>
	</receiver>
	<service android:enabled="true" android:name=".MyService"/>
    </application>
</manifest>
选择相同类型的应用
Intent audioIntent = new Intent(Intent.ACTION_GET_CONTENT);
audioIntent.setType("audio/*");
startActivity(Intent.createChooser(audioIntent,"选择音频程序"));


被调起Activity 中添加过滤代码
<intent-filter android:label="应用列表中显示的名字">
    <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="audio/*" />
</intent-filter>
发送Email
Intent sendEmailIntent = new Intent(Intent.ACTION_SEND);
//指定要发送的目标Email
sendEmailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"techcast@126.com"});
//指定两个抄送的Email地址
sendEmailIntent.putExtra(Intent.EXTRA_CC,new String[]{"abc@126.com","test@126.com"});
//指定Email标题
sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT,"关于Android的两个技术问题");
//指定Email内容
sendEmailIntent.putExtra(Intent.EXTRA_TEXT,"1.如何调用其他应用程序中的Activity?\n2.在应用程序中如何调用系统广播?");
//指定Email的内容为纯文本
sendEmailIntent.setType("text/plain");
//建立一个自定义选择器,并有用户选择使用哪一个客户端发送消息
startActivity(Intent.createChooser(sendEmailIntent,"选择发送消息的客户端"));
Re-installation failed due to different application signatures
这些核心应用安装在sdk_dir\tools\lib\images\system.img中
	我们需要做的就是重新生成一个这些核心app的system.img(具体不包含哪些根据实际需要选择,如果都删除模拟器无法启动,建议调试哪个删除哪个)
	生成system.img方法:
删除源码编译路径/android/out/target/product/generic/system/app 中要删除的 *.apk
在源码根目录下执行 > make snod
半分钟就可以重新生成一个system.img 不包含删除的app
把这个重新生成的system.img拷贝覆盖掉 
	 sdk_dir\tools\lib\images\system.img 
  
这样我们修改的核心app就可以在eclipse + emulator 下调试了
android listView焦点问题
今天解决了一个Android平台下的焦点问题。发现其中关键问题的所在是Android的touchMode。从JavaSwing平台过来的人,都会关注setFocusable()和requestFocus()方法,但是在Android的View中还有另外的两个个方法,setFocusableInTouchMode()和requestFocusFromTouch()方法。这个两个方法就是解决Android上的焦点获取问题的关键。

同时在View类中,还有一个isInTouchMode(),可以帮助我们在监听Focuse事件时判断是否执行click(). 代码如下:

 

 

    ImageButton.OnFocusChangeListener mFocusChangeListener = new ImageButton.OnFocusChangeListener(){
        
        public void onFocusChange(View v, boolean hasFocus) {
            Log.d("FocuseChange", "Focuse has changed.");
              if (hasFocus) {

                       // 如果是touchmode就执行click,否则就会只是选中。 
                  v.setBackgroundDrawable(getResources().getDrawable(R.drawable.));

                  if (v.isInTouchMode()){ 

                      ((ImageButton)v).performClick();
                  } 
              } else {
                  v.setBackgroundDrawable(getResources().getDrawable(R.));
                  v.getBackground().setAlpha(100);
              }
            
        }
    };

两个ListView的焦点问题
两个ListView的焦点问题: 
两个ListView只能使其中一个获取焦点而另外一个无法获取到焦点,可以通过以下方法强制转移焦点。 

listView2.setFocusable(true); 
listView2.setFocusableInTouchMode(true); 
listView2.requestFocus(); 
listView2.requestFocusFromTouch(); 
ListView1.clearFocus(); 
以上代码可以将焦点从listView1上移动到listView2上来。
mk.sh
#!/bin/bash

while true
do
procrank >> /sdcard/track.log
sleep 3
done
通知
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification no = new Notification(R.drawable.icon,"XX",System.currentTimeMillis());
Intent contentIntent = new Intent(this,XX.class);
PendingIntent contentIntent = PendingIntent.getActivity(context,requestCode, intent, flags);
no.setLatestEventInfo(contextcontentTitle, contentText, contentIntent);
nm.notify(NOTIFICATION_ID,no);
正确设置全屏并去除启动时只有title的问题
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,      
                      WindowManager.LayoutParams. FLAG_FULLSCREEN);   
这样做有一个缺点是,运行有短暂时候不是全屏,有状态栏,然后才显示全屏。
正确的设置方法为:
AndroidManifest.xml中加入android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Global site tag (gtag.js) - Google Analytics