Android : Not work Every time PhoneStateListener Android

on Thursday, July 31, 2014


I have Developing Application of Full Caller Id. In that dynamic screen call at the time of Incoming call / After Missed Call. Now this is work one time. When i received call. Than after it is not work or Not call any dynamic screen at the time Incoming call/ Missed call.




I have very confuse about my problem.



Context c;
boolean cut, flag = true;
PhoneStateListener listener;
SharedPreferences prefs;
static boolean ring = false;
static boolean callReceived = false;

public MyPhoneStateListener(Context c) {
// TODO Auto-generated constructor stub
this.c = c;
}

@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);

Log.d("main", "incoming call receiver.");
PowerManager pm = (PowerManager) c
.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();

switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.v("idle state", "CALL_STATE_IDLE");
// CALL_STATE_IDLE;


if (ring == true && callReceived == false && CheckMissCall.isReject==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;



}



}

0 comments:

Post a Comment