Android的外播电话拦截器,在拨打电话时,若所拨打电话与要拦截号码相同,则拦截该号码,不进行外拨。

1.布局文件如下所示

activity_main.xml:



 

    

 

    
2.逻辑代码:
MainActivity.java:
package com.lfsy.ljdh;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private SharedPreferences sp;
	private EditText et_number;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		et_number = (EditText) findViewById(R.id.et_number);
	}

	public void save(View v) {
		String number = et_number.getText().toString();
		sp = getSharedPreferences("config", Context.MODE_PRIVATE);
		Editor edit = sp.edit();
		edit.putString("number", number);
		edit.commit();
		Toast.makeText(this, "设置成功", 0).show();
	}

}

3.类的建立
MyReceiver.java:
package com.lfsy.ljdh;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		String outCallNumber = getResultData();
		SharedPreferences sp = context.getSharedPreferences("config",
				Context.MODE_PRIVATE);
		String number = sp.getString("number", " ");
		if (number.equals(outCallNumber)) {
			setResultData(null);
		}
	}
}

4.清单文件注册:


            
                
            
        
5.权限的配置:



你可能感兴趣的:(Android的外播电话拦截器,在拨打电话时,若所拨打电话与要拦截号码相同,则拦截该号码,不进行外拨。)