0

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

4

1 回答 1

0

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

第一步:

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

先编码,然后测试。

第二步:

在 goto next 活动中创建一个意图。

  Intent intent = new Intent(NextActivity.class)
  startActivity(intent);
于 2012-08-03T21:50:34.993 回答