1. manifest file
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.ipdail"Android:versioncode= "1"Android:versionname= "1.0" > <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" /> <uses-permissionAndroid:name= "Android.permission.PROCESS_OUTGOING_CALLS"/> <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" > <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" > <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> </Intent-filter> </Activity> <receiverAndroid:name=". Outcallreceiver "> <Intent-filter> <ActionAndroid:name= "Android.intent.action.NEW_OUTGOING_CALL" /> </Intent-filter> </receiver> </Application></Manifest>
2.layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context= "Com.example.ipdail.MainActivity" > <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Please enter IP phone to set" /> <EditTextAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/et_ip"Android:inputtype= "Phone" /> <ButtonAndroid:onclick= "click"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Settings" /></LinearLayout>
3.activity
PackageCom.example.ipdail;Importandroid.content.SharedPreferences;ImportAndroid.content.SharedPreferences.Editor;ImportAndroid.os.Bundle;Importandroid.support.v7.app.ActionBarActivity;Importandroid.text.TextUtils;ImportAndroid.view.View;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classMainactivityextendsactionbaractivity {PrivateEditText et_ip; PrivateSharedpreferences sp; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Et_ip=(EditText) Findviewbyid (R.ID.ET_IP); SP= getsharedpreferences ("IP", mode_private); String IP= sp.getstring ("IP", "" "); Et_ip.settext (IP); } Public voidClick (View view) {String IP=Et_ip.gettext (). toString (). Trim (); if(Textutils.isempty (IP)) {Toast.maketext ( This, "Set IP cannot be empty", 0). Show (); return; } Editor Editor=Sp.edit (); Editor.putstring ("IP", IP); Editor.commit (); Toast.maketext ( This, "set success", 0). Show (); } }
4.OutCallReceiver
PackageCom.example.ipdail;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;Importandroid.content.SharedPreferences; Public classOutcallreceiverextendsBroadcastreceiver {//The OnReceive method is executed when a broadcast leave is generated.@Override Public voidOnReceive (Context context, Intent Intent) {//get a phone number for outgoing callsString number =Getresultdata (); //Replace this number .Sharedpreferences sp = context.getsharedpreferences ("IP", context.mode_private); String IP= sp.getstring ("IP", "" "); String Newnumber= IP +Number ; //set up outgoing phone numbersSetresultdata (Newnumber); }}
Android Broadcastreceiver components simple to use