android IP拨号器

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


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


新建一个android项目 IPDialer


CallBroadcastReceiver.java广播接受者


public class CallBroadcastReceiver extends BroadcastReceiver {

	@Override
	public 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值