1. Are you ready for the Galaxy S20? Here is everything we know so far!

Phone state listener called multiple times

Discussion in 'Android Help' started by bhagavathram, Oct 6, 2014.

  1. bhagavathram

    bhagavathram Guest
    Thread Starter

    Hi all ,
    When i try to detect incoming calls with phonestatelistener, it excites multiple times. This is my code. onCallStateChanged method is called multiple times.

    1. onCallStateChanged o Service
    2 .public int onStartCommand(Intent intent, int flags, int startId)
    {
    callHelper = new CallHelper(this);
    callHelperl.start

    }

    -------------
    callHelper.java

    public void start()
    {

    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    }

    private class CallStateListener extends PhoneStateListener
    {

    Context context;
    public void PhoneStateListener(Context context)
    {
    this.context = context;
    }
    @Override
    public void onCallStateChanged(int state, final String incomingNumber)
    {
    System.out.println("onCallStateChanged Method" +state );

    String ip = null;

    switch (state)
    {

    case TelephonyManager.CALL_STATE_RINGING:
    sysout("call ring ")
    break;
    }
    }
    }


    Thanks in advance.
    bhagavath
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Phone state listener
  1. Raycomp
    Replies:
    1
    Views:
    202
  2. ely franco
    Replies:
    7
    Views:
    359
  3. AntiMorrisey
    Replies:
    2
    Views:
    383
  4. kgash
    Replies:
    4
    Views:
    329
  5. Justin Raney
    Replies:
    9
    Views:
    463
  6. Justin Raney
    Replies:
    10
    Views:
    397
  7. spman
    Replies:
    4
    Views:
    440
  8. RVDowning
    Replies:
    13
    Views:
    535
  9. Justin Raney
    Replies:
    6
    Views:
    429
  10. thunderlumber
    Replies:
    15
    Views:
    545

Share This Page

Loading...