测试。做一个Receiver监听手机通话状态。发现这样个问题。
package com.duduli.call;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.pm.PackageStats;import android.os.Bundle;import android.telephony.PhoneStateListener;import android.telephony.SmsManager;import android.telephony.TelephonyManager;public class CallComingReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubTelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);//System.out.println("a");tm.listen(MyPhoneState.getInstance(), PhoneStateListener.LISTEN_CALL_STATE);//System.out.println("b");////Bundle b = intent.getExtras();//String phoneNr= b.getString("incoming_number");//if(phoneNr != null){//System.out.println(phoneNr);//}//System.out.println(tm.getLine1Number());}}


package com.duduli.call;import android.telephony.PhoneStateListener;import android.telephony.TelephonyManager;public class MyPhoneState extends PhoneStateListener{private int last_state = TelephonyManager.CALL_STATE_IDLE;private MyPhoneState(){}private static MyPhoneState mps = null;public static MyPhoneState getInstance(){if(mps == null){mps = new MyPhoneState();}return mps;}@Overridepublic void onCallStateChanged(int state, String incomingNumber) {// TODO Auto-generated method stub//super.onCallStateChanged(state, incomingNumber);switch (state) {case TelephonyManager.CALL_STATE_IDLE://System.out.println("空闲时间");//System.out.println("CALL_STATE_IDLE");last_state = TelephonyManager.CALL_STATE_IDLE;break;case TelephonyManager.CALL_STATE_OFFHOOK://System.out.println("CALL_STATE_OFFHOOK");break;case TelephonyManager.CALL_STATE_RINGING:if(last_state == TelephonyManager.CALL_STATE_IDLE){System.out.println("发送邮件0------?");last_state = TelephonyManager.CALL_STATE_RINGING;}//System.out.println("来电了");//System.out.println("CALL_STATE_RINGING");break;default:break;}}}; 


不知怎么回事,我这边调试的结果,总会这样。
第一次呼入会出现一个“来电了”。
但是挂断之后就会出现两个“空闲时间”
再次呼入又会出现两个“来电了”
……以后的都是出现两次状态。
我都把实现都弄成了单例了还是出现问题,都不知道在哪里的问题。

有没有大神给指点下。

更多相关文章

  1. android之获取系统时间并作为文件名
  2. Android自定义view七时间轴(二)---横向的图表时间轴
  3. Android 隐藏状态栏 和 标题栏
  4. Android TimePickerDialog(原生安卓时间选择器)
  5. androidの4.4版本沉浸式透明状态栏与导航栏案例
  6. Android 屏幕方向以及UI界面状态的保存

随机推荐

  1. Android(安卓)利用ViewPager+GridView,仿
  2. 最近用android写的一个项目,开发心得
  3. Android锁屏后主Activity的onDestroy方法
  4. uniapp自定义弹窗组件|Modal模态框|Loadi
  5. Android(安卓)init进程--属性服务器
  6. android onCreate中获取view宽高为0的多
  7. 在 Android(安卓)11 及更高版本系统中处
  8. Android集成ShareSDK第三方分享和登录
  9. Android之自定义最简单的竖向引导页
  10. 自定义React Native Modal,支持全屏弹框