android如何截获拨号

     用户在系统的拨号应用中输入完号码并且按拨号键后,还没真正拨出去前,我想作一些操作。比如修改号码或者检查权限。

     思考了很久,觉得系统的拨号动作应该还是发送一个intent,理论上是可以截获的。 终于,在开源工程sipUA中看到了方法。如下:

     首先,仔细看看API中关于intent.ACTION_NEW_OUTGOING_CALL的描述。写得很多很详细,节选一部分“You must hold the PROCESS_OUTGOING_CALLS permission to receive this Intent.This is a protected intent that can only be sent by the system”。

 

     系统拨号动作其实就是发送了一个包含这样一个intent的Broadcast Action。我们可以写个receiver来获得此intent. 如sipUA中:

    <receiver android:name=".ui.Caller">
         <intent-filter android:priority="-1">
          <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
         </intent-filter>
     </receiver>

需要注意的是 android:priority="-1"  为什么截获这个intent需要这样设置,可以参考API中的说明。当然还要注意加上

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>

你可能感兴趣的:(android,api,System,action)