Broadcastreceiver is the broadcast receiver, and the system will send some broadcasts when the event is generated, such as booting, calling, etc...
The broadcastreceiver can then receive these broadcasts for operation.
All we have to do today is to add the previous IP number when dialing the number.
First we want to register a broadcastreceiver, and then we want to configure some information in the manifest file first we need to make clear what this broadcastreceiver is going to receive.
Broadcasting.
<receiver android:name= "Com.example.ipcall.MyReceiver" >
<intent-filter>
<action android:name= "Android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
This will make sure that the radio is sent when the call is received, and then added in the permissions.
<uses-permission android:name= "Android.permission.PROCESS_OUTGOING_CALLS"/>
PackageCom.example.ipcall;ImportAndroid.os.Bundle;Importandroid.app.Activity;Importandroid.content.SharedPreferences;ImportAndroid.content.SharedPreferences.Editor;ImportAndroid.view.Menu;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.EditText; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Findviewbyid (R.ID.BTN). Setonclicklistener (NewOnclicklistener () {@Override Public voidOnClick (View arg0) {//TODO auto-generated Method StubEditText EDT =(EditText) Findviewbyid (R.ID.IP); String Ipnumber=Edt.gettext (). toString (); Sharedpreferences SP= Getsharedpreferences ("number", mode_private); Editor Editor=Sp.edit (); Editor.putstring ("IP", Ipnumber). commit (); } }); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {//inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.main, menu); return true; }}
PackageCom.example.ipcall;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;Importandroid.content.SharedPreferences; Public classMyreceiverextendsBroadcastreceiver { PublicMyreceiver () {} @Override Public voidOnReceive (Context context, Intent Intent) {//Todo:this method is called if the Broadcastreceiver is receiving//An Intent broadcast.System.out.println ("On the Phone"); //get the number on the phoneString number =Getresultdata (); Sharedpreferences SP= Context.getsharedpreferences ("number", context. Mode_private); String IP= sp.getstring ("IP", "" "); //set up the phone, okay?Setresultdata (ip+Number ); }}
<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:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity "android:orientation= "vertical"> <EditTextAndroid:id= "@+id/ip"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter"/> <ButtonAndroid:id= "@+id/btn"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" /></LinearLayout>
Android four components of the Broadcastreceiver IP dialing function