项目有一个监听来电并做一个弹窗的需求。
于是乎首先想到的是静态注册,然而在运行过程中发现,只能让弹窗显示,移除弹窗的时候缺没有移除。。。
<receiver android:name=".PhoneStateReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE</span>
</intent-filter>
</receiver>
下面代码是根据网上的代码改的,项目代码就不贴了,都懂得。。。
http://www.iteye.com/topic/1118711 这是传送门
WindowManager wm;TextView tv;
public void onReceive(Context context,Intent intent){
String action = intent.getAction();
if(action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)){
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
int state = telephony.getCallState();
if(state == TelephonyManager.CALL