1、创建activity_main.xml
2、创建MainActivity.java类
package com.example.ipdail;import android.os.Bundle;import android.app.Activity;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.view.View;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity { private EditText et_number; private SharedPreferences sp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_number = (EditText) findViewById(R.id.editText1); sp=getSharedPreferences("config", MODE_PRIVATE); String ipNumber=sp.getString("number", ""); et_number.setText(ipNumber); } public void click(View view) { Editor editor=sp.edit(); editor.putString("number", et_number.getText().toString().trim()); editor.commit(); Toast.makeText(this, "设置完成", 0).show(); }}
3、编写OutCallReceiver.java类
/** * */package com.example.ipdail;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.graphics.AvoidXfermode.Mode;/** * @author hyzhou * * 2013-12-5 */public class OutCallReceiver extends BroadcastReceiver { /* (non-Javadoc) * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent) */ @Override public void onReceive(Context context, Intent intent) { // 获得外拨电话号码 String number=getResultData(); SharedPreferences sp=context.getSharedPreferences("config",context.MODE_PRIVATE); String ipnumber=sp.getString("number", ""); String newnumber=ipnumber+number; setResultData(newnumber); }}
4、注册广播AndroidManifest.xml
>