0

i'have confuse about my code. I'm open activity it the time of Incoming Call/ Missed Call. But its open only 1st time till the received call. after receiving 1st call Not work Ringing state.

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;

Broadcast Receiver

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);
        }



    }

Now what i have to do ..??

  • your question is not clear, what you want to do, n what you did tell this – nawaab saab Aug 05 '14 at 06:08
  • on 1st time of incoming call/ Missed call dynamic activity open run fine. but when i received call. than after not call any dynamic screen like incoming call/ missed call. – user3883019 Aug 05 '14 at 06:20
  • do you want whenever there is a incoming call in your mobile, a activity must start, am i right? – nawaab saab Aug 05 '14 at 06:40
  • ya Every time of Incoming call Dynamic Activity must be start. also at the time of Missed call. or At the the time of Cut the Received call. – user3883019 Aug 05 '14 at 06:47
  • so you want to start a activity after a misscall or received call, it means when the phone is in idle state, right? – nawaab saab Aug 05 '14 at 06:50
  • i want to open activity at the time of Incoming call. At the time of Missed call, and after cut the received call CallLog.class Activity open. – user3883019 Aug 05 '14 at 06:53
  • after received call open CallLog activity or aftre Missed call open Misscall Activity. or at the time of incoming call Open dynamis Unlock_hud Activity. – user3883019 Aug 05 '14 at 06:56
  • so are you using broadcastreceiver for this? – nawaab saab Aug 05 '14 at 06:58
  • this code is phoneStateListener. or i also use broadcasst Receiver for this.. i post this code in my question. – user3883019 Aug 05 '14 at 07:00

1 Answers1

0

I'd put a breakpoint in there and test where the logic goes that you don't expect it to. It looks like you aren't properly resetting some of your state variables. But I have a working version of a call detector here Get phonenumber programmatically - Android and a blog post describing how it works at http://gabesechansoftware.com/is-the-phone-ringing/

Community
  • 1
  • 1
Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127