private static final String ACTION_IN = "androID.intent.action.PHONE_STATE";
下面是broadCastReceiver的onReceIEve()的代码
public voID onReceive(Context context,Intent intent) { ctx = context; if (intent.getAction().equals(ACTION_IN)) { Log.v("onReceive","ACTION IN"); if ((bundle = intent.getExtras()) != null) { Log.v("onReceive","Bundle != NulL"); state = bundle.getString(TelephonyManager.EXTRA_STATE); Log.v("onReceive","state: "+state); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { //businesslogic } } } }
我在清单中有以下许可
<uses-permission androID:name="androID.permission.READ_PHONE_STATE"/>
我的接收器在清单中定义为此
<receiver androID:name="IncomingCallinterceptor" > <intent-filter androID:priority="999"> <action androID:name="androID.intent.action.PHONE_STATE"/> </intent-filter> </receiver>解决方法 试试这个,它没有在EXTRA_STATE_RINGING上实现业务逻辑,它只在用户断开调用(CALL_STATE_IDLE)后设置.
public voID onReceive(Context context,"Bundle != NulL"); state = bundle.getString(TelephonyManager.EXTRA_STATE); Boolean singlecallstate=false; switch (state) { case TelephonyManager.EXTRA_STATE_RINGING: singlecallstate=true; //any other code you want case TelephonyManager.CALL_STATE_IDLE: if(singlecallstate){ //business logic singlecallstate=false; } } }}总结
以上是内存溢出为你收集整理的android – 广播接收器调用两次EXTRA_STATE_RINGING状态,导致不变数据全部内容,希望文章能够帮你解决android – 广播接收器调用两次EXTRA_STATE_RINGING状态,导致不变数据所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)