在需要添加的activity添加如下即可:
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
-------------------
根据之前对于IntentFilter的描述,从硬件键盘的拨号键启动程序需要我们在TinyDialer中加入一条新的IntentFilter。我们先来看看在AndroidManifest.xml中关于IntentFilter的描述是什么。
- <intent-filter>
- <action android:name="android.Intent.Action.MAIN" />
- <category android:name="android.Intent.Category.LAUNCHER" />
- intent-filter>
目前只有一条IntentFilter,它的动作名称是Action.MAIN,类别名称是Category.LAUNCHER。正是有了这条IntentFilter,TinyDialer的图标才出现在了应用程序选择的菜单里。
为了新加入拨号键启动TinyDialer,我们加入:
- <intent-filter>
- <action android:name="android.Intent.Action.CALL_BUTTON"/
- <category android:name="android.Intent.Category.DEFAULT" />
- intent-filter>
更改后的效果怎么样?当你按下键盘左下角绿色的拨号键时,系统会弹出一个窗口提醒用户,选择启动TinyDialer还是选择Android自带的拨号程序如图所示。
这 个例子很好地说明了隐式Intent的用法。TinyDialer声明自己的IntentFilter的行为是ACTION.CALL_BUTTON,以 后每次用户按下拨号键时,Android系统都会将拨号键的意图和所有声明过ACTION.CALL_BUTTON的IntentFilter进行比较, 然后将匹配的组件提供给用户选择。