使用IntentFilter的拨号程序

在需要添加的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的描述是什么。

 
 
  1. <intent-filter> 
  2. <action android:name="android.Intent.Action.MAIN" /> 
  3. <category android:name="android.Intent.Category.LAUNCHER" /> 
  4. intent-filter> 

目前只有一条IntentFilter,它的动作名称是Action.MAIN,类别名称是Category.LAUNCHER。正是有了这条IntentFilter,TinyDialer的图标才出现在了应用程序选择的菜单里。

为了新加入拨号键启动TinyDialer,我们加入:

 
 
  1. <intent-filter> 
  2. <action android:name="android.Intent.Action.CALL_BUTTON"/  
  3. <category android:name="android.Intent.Category.DEFAULT" /> 
  4. intent-filter> 

更改后的效果怎么样?当你按下键盘左下角绿色的拨号键时,系统会弹出一个窗口提醒用户,选择启动TinyDialer还是选择Android自带的拨号程序如图所示。

 

这 个例子很好地说明了隐式Intent的用法。TinyDialer声明自己的IntentFilter的行为是ACTION.CALL_BUTTON,以 后每次用户按下拨号键时,Android系统都会将拨号键的意图和所有声明过ACTION.CALL_BUTTON的IntentFilter进行比较, 然后将匹配的组件提供给用户选择。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

L_serein

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值