The UI is defined in the layout file, although there is no UI .....
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:orientation=" vertical " android:layout_height= "Match_parent" tools:context= ". Mainactivity "> <textview android:layout_width=" wrap_content " android:layout_height=" Wrap_ Content " android:text=" @string/hello_world "/><edittext android:id=" @+id/et_number " android: Layout_width= "Fill_parent" android:layout_height= "wrap_content" android:inputtype= "Phone" /> <button android:layout_height= "wrap_content" android:layout_width= "fill_parent" android:text = "Save IP number" android:onclick= "save" /></linearlayout >
Implementing part of the code in Mainactivity
Package Com.wzw.ipdial;import Android.app.activity;import Android.content.sharedpreferences;import Android.content.sharedpreferences.editor;import Android.os.bundle;import Android.text.textutils;import Android.view.view;import Android.widget.edittext;import Android.widget.toast;public class MainActivity extends Activity {private EditText etnumber;private sharedpreferences sp; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); EtNumber= ( EditText) Findviewbyid (r.id.et_number) sp=getsharedpreferences ("config", mode_private);} public void Save (View v) {String ipnumber=etnumber.gettext (). toString (). Trim (); if (Textutils.isempty (Ipnumber)) { Toast.maketext (This, "Clear IP number succeeded", 0). Show (); Else{toast.maketext (This, "Set IP number succeeded", 0). Show (); Editor Editor=sp.edit (); Editor.putstring ("Ipnumber", Ipnumber); Editor.commit ();}}
Create a new class to inherit the broadcast recipient
Package com.wzw.ipdial;/** * Defines a radio */import android.content.broadcastreceiver;import android.content.Context; Import Android.content.intent;import Android.content.sharedpreferences;import Android.util.log;public class Ipdial Extends Broadcastreceiver {@Overridepublic void OnReceive (context context, Intent Intent) {//TODO auto-generated method s Tubstring Number=getresultdata (); Sharedpreferences sp=context.getsharedpreferences ("config", context. Mode_private); String ipnumber=sp.getstring ("Ipnumber", ""); Setresultdata (Ipnumber+number);}}
Permissions in the manifest file
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.wzw.ipdial "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk A ndroid:minsdkversion= "8" android:targetsdkversion= "/> <uses-permission android:name=" Android.permissio N.process_outgoing_calls "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_laun Cher "android:label=" @string/app_name "android:theme=" @style/apptheme "> <activity A Ndroid:name= "com.wzw.ipdial.MainActivity" android:label= "@string/app_name" > <intent-filter> ; <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> </activity> <!--set up the broadcast receiver and specify the action to receive the call-- <receiver andRoid:name= "com.wzw.ipdial.Ipdial" > <intent-filter > <action android:name= "android.in Tent.action.NEW_OUTGOING_CALL "/> </intent-filter> </receiver> </application> </manifest>