Android 电话结束时更改活动

Android 电话结束时更改活动,android,eclipse,telephonymanager,Android,Eclipse,Telephonymanager,我想知道如何使用Android中的TelephonyManager更改电话通话结束时的活动。任何人都有教程或可以提供代码?要更改活动,您可以在TelephonyManager上注册为侦听器,或收听更改的广播。在那一刻,你将通过执行context.startActivity(INTE)来改变活动,意图是针对下一个活动 Intent intent = new Intent(NextActivity.class) startActivity(intent); 第一步: 向TelephonyM

我想知道如何使用Android中的TelephonyManager更改电话通话结束时的活动。任何人都有教程或可以提供代码?

要更改活动,您可以在TelephonyManager上注册为侦听器,或收听更改的广播。在那一刻,你将通过执行context.startActivity(INTE)来改变活动,意图是针对下一个活动

  Intent intent = new Intent(NextActivity.class)
  startActivity(intent);
第一步:

向TelephonyManager注册PhoneStateListener,以便在状态更改为“断开连接”时捕获

   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);
首先编写代码,然后进行测试

第二步:

在转到下一个活动中创建意图

  Intent intent = new Intent(NextActivity.class)
  startActivity(intent);

如果您对检索管理器、附加侦听器或启动切换活动的意图有疑问,请告知我们。服务和活动都是从上下文派生的,因此都有startActivity()方法。您希望首先测试您是否接收到意图,并能够正确识别状态更改。然后通过startActivity()方法切换到下一个活动。您还可以在intent中放入参数,并在需要时将调用信息传递给下一个活动。好的,那么在它表示changed to disconnected的行中,我必须将call_STATE_OFFHOOK,对吗?另外,在步骤2中括号中的intent中,它给了我一个错误,显示:令牌“intent”上的语法错误,此标记后应为VariableDeclaratorId。