ip拨号器demo----BroadcastReceiver

ip拨号器demo----BroadcastReceiver_第1张图片

新建一个class类,继承BroadcastReceiver

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class CallReceiver extends BroadcastReceiver {

	//收到广播时调用
	public void onReceive(Context context, Intent intent) {
		// 取出广播中的号码
		String number = getResultData();
		//添加新号码
		String newNumber = "17951" +number;
		//把修改后的号码放到广播中
		setResultData(newNumber);
	}

}


清单文件注册,并添加权限

</pre><pre>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!-- 注册广播 -->
        <receiver 
            android:name="com.demo_opcall.CallReceiver">
            <!-- 指定要接受的广播类型    电话广播-->>
            <intent-filter >
                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
            </intent-filter>
        </receiver>



你可能感兴趣的:(ip拨号器demo----BroadcastReceiver)