android IP拨号器

来源:互联网 发布:算法分析与设计答案 编辑:程序博客网 时间:2024/04/29 08:37

在有些app中,有IP拨号的功能,这个功能就是当我们打电话出去的时候,在电话基础上加些区号或者打长途的时候加上比如17951就可以省点话费,今天就模仿的实现下此功能.


我们知道在系统打电话出去时,系统是会发出一个广播的,然后获取刚拨打的电话号码,再在电话号码之前加上区号等等,就实现了IP拨号器


新建一个android项目 IPDialer


CallBroadcastReceiver.java广播接受者


public class CallBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {Log.e("CallBroadcastReceiver","我是否执行了");String number = getResultData();setResultData("0571"+number);}}

因为广播也是四大组件之一,也必须在<span style="font: 24px/36px 楷体; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">AndroidManifest.xml   中注册,</span>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.ipdialer"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="18" /><uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <receiver             android:name="com.example.ipdialer.CallBroadcastReceiver"            >            <intent-filter>                 <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>            </intent-filter>        </receiver>         <activity            android:name="com.example.ipdialer.MainActivity"             >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>
记住:别忘记了权限,因为这也是要侵犯用户的隐私,所以要加上权限


还有一点:在2.3以下系统中,如果项目中只有 activity, 是可以的,但是在4.0系统上必须要有一个activity,否则广播无效,因为无activity,在桌面上没app图标,这会给一些想法不单纯的人开发对用户带来不好的app,因此google在4.0上修复了这个算bug吧

<span style="font: 24px/36px 楷体; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"></span>





0 0
原创粉丝点击