我对我的代码感到困惑。我打电话/未接电话时打开活动。但它只在第一次打开,直到接到电话。收到第一个电话后不工作振铃状态。
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.v("idle state", "CALL_STATE_IDLE");
// CALL_STATE_IDLE;
if (ring == true && callReceived == false && CheckMissCall.isRunning== false) {
Log.v("missed call", "Missed call from : " + incomingNumber);
if(CheckMissCall.isShown)
{
c.stopService(new Intent(c, Unlock_hud.class));
}
flag = true;
if (prefs.getBoolean("main_state", true))
{
Intent inter = new Intent(c, MissCall.class);
inter.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
inter.putExtra("CellNumber", incomingNumber);
c.startActivity(inter);
}
}
if(ring == true && callReceived == true && CheckMissCall.isReject == true)
{
Intent inter = new Intent(c, callLog.class);
inter.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.startActivity(inter);
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
// CALL_STATE_OFFHOOK;
callReceived = true;
Log.v("call received", "CALL_STATE_OFFHOOK " + incomingNumber);
break;
case TelephonyManager.CALL_STATE_RINGING:
ring = true;
// CALL_STATE_RINGING
Log.v("call ringing", "CALL_STATE_RINGING " + incomingNumber);
Log.d("flags", "flags: " + flag);
if (flag ) {
//cut = true;
//flag = false;
CheckMissCall call = new CheckMissCall(c);
call.setName(incomingNumber);
call.setNumber4Sms(incomingNumber);
call.setContactPhoto();
Log.d("main", "state ringing");
prefs = PreferenceManager.getDefaultSharedPreferences(c);
if (!prefs.getBoolean("main_state", false))
{
return;
}
/* if (!isScreenOn && CheckMissCall.isRunning) {
return;
}*/
if (CheckMissCall.isRunning) {
return;
}
else {
Log.d("main", "EEEEEEEEEEEEEEEE: Unlock hud");
Intent in = new Intent(c, Unlock_hud.class);
in.setFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
c.startService(in);
// c.stopService(new Intent(c, Unlock_hud.class));
}
}
break;
广播接收器
public void onReceive(final Context context, Intent intent) {
Log.d("main", "receive");
cut = false;
prefs = PreferenceManager.getDefaultSharedPreferences(context);
// String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
TelephonyManager tmanager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (listener == null) {
listener = new MyPhoneStateListener(context);
if (prefs.getBoolean("main_state", false)) {
tmanager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
现在我要做什么.. ??
答案 0 :(得分:0)
我在那里放了一个断点,并测试你不希望它出现的逻辑。看起来您没有正确重置某些状态变量。但是我在Get phonenumber programmatically - Android有一个有效的呼叫检测器版本,还有一篇博客文章描述了它在http://gabesechansoftware.com/is-the-phone-ringing/的工作原理