0

I heard that we can not use TelephonyManager for detecting Incoming/Missed/Dialed calls from Android version 2.3 and above. Is this true? Incase yes, Do we have any workaround for handling the calls? Please suggest. Im in urgent need of it.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
Srinath Reddy
  • 289
  • 1
  • 3
  • 4

1 Answers1

0

Check this post. It will help.

You can query it.

Please find the code to use TelephonyManager. I tried in 2.3.3 and is working for me :

public class MainActivity extends Activity {

private TelephonyManager telephonyManager;
private PhoneStateListener listener;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Create a new PhoneStateListener
    listener = new PhoneStateListener() {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            String stateString = "N/A";
            switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
                stateString = "Idle";
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                stateString = "Off Hook";
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                stateString = "Ringing";
                break;
            }
            Log.i("DEMO",
                    String.format("\nonCallStateChanged: %s", stateString));
        }
    };

    telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

}

In Manifest, you need to put the permission :

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Community
  • 1
  • 1
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
  • I need the data at that instance. Is there any help? – Srinath Reddy Aug 28 '12 at 05:31
  • I think you can use the TelephonyManager for that..it will work. I dint see anything stating it will not work on 2.3+. can you please share the post which says that? – Eldhose M Babu Aug 28 '12 at 05:39
  • It is not the post. I wrote the code which I have taken form these forums and tested in those mobiles. But, no use :( – Srinath Reddy Aug 29 '12 at 09:47
  • Please find the edited answer to use TelephonyManager to listen Phone State changes. I tried in 2.3.3 code base on emulator running in 4.0 and is working fine. – Eldhose M Babu Aug 30 '12 at 05:22