0

I would like to know how to change activities on an end of a phone call using the TelephonyManager in Android. Anybody have a tutorial or can provide code?

  • If you have questions on retrieving manager, attaching listener, or firing off intent to switch activities let us know. Both Services and Activities derive from context so both have the startActivity() method. – Code Droid Aug 03 '12 at 22:02
  • You want to first test that you are receiving the intent, and can recognize the state change correctly. Then do the switch via startActivity() method to the next activity. You an also put parameters in the intent as well to pass information on the call to the next activity if you need to. – Code Droid Aug 03 '12 at 22:03

1 Answers1

0

To change activities you would register as a listener on the TelephonyManager, or listen for a broadcast of the change. At that moment you would change activities, by doing context.startActivity(inent) where the intent is aimed at the next activity.

Step One:

Register a PhoneStateListener with the TelephonyManager to catch when the state changes to diconnected.

   PhoneStateListener myPhoneStateListener = new PhoneStateListener() {
     @Override
    void onCallStateChanged(int state, String incomingNumber){
       // Check state here.
       if (changed to disconnected){  // Check status change here. Might need to save previous?
          Intent i = new Intent(NextActivity.class);
          startActivity(i);
       }
      }
}

 telephonyManager.listen(myPhoneStateListener);

Code this first, and test.

Step Two:

Create an intent in the goto next activity.

  Intent intent = new Intent(NextActivity.class)
  startActivity(intent);
Code Droid
  • 10,344
  • 17
  • 72
  • 112
  • Okay so at the line where it says changed to disconnected, I would have to put CALL_STATE_OFFHOOK, correct? – user1561917 Aug 04 '12 at 01:08
  • Also, on the intent in the parentheses in step two, it gives me an error that says: Syntax error on token "intent", VariableDeclaratorId expected after this token. – user1561917 Aug 04 '12 at 01:13