Android:如何在我的 Activity 中启动电话,然后再返回?

标签 android android-activity return phone-call

我可以通过Intent发起电话:

    String url = "tel:3334444";
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));

但它会停留在电话屏幕上。我想要的是留在我的应用程序 Activity 中。是否有可能在后台启动电话?或立即返回到之前的 Activity 。

最佳答案

你需要在你的activity中实现Phonecall状态

////处理手机状态

private PhoneStateListener phoneListener = new PhoneStateListener() {
      public void onCallStateChanged(int state, String incomingNumber) {
       try {
        switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
         Toast.makeText(activity.this, "CALL_STATE_RINGING", Toast.LENGTH_SHORT).show();
         mediaPlayer.pause();
         break;
        case TelephonyManager.CALL_STATE_OFFHOOK:
        Toast.makeText(activity.this, "CALL_STATE_OFFHOOK", Toast.LENGTH_SHORT).show();
         mediaPlayer.pause();
         break;
        case TelephonyManager.CALL_STATE_IDLE:
        Toast.makeText(activity.this, "CALL_STATE_IDLE", Toast.LENGTH_SHORT).show();
         mediaPlayer.start();
         break;
        default:
        Toast.makeText(activity.this, "default", Toast.LENGTH_SHORT).show();

        }
       } catch (Exception e) {

       }
      }
     };  

关于Android:如何在我的 Activity 中启动电话,然后再返回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8074391/

相关文章:

android - 导航器抽屉标题图像未在 Firebase 查询中设置

java - Android - AudioRecord 在channel_in_stereo 中分割2 个 channel

c++ - 在模板函数上的 try/catch block 后返回

java - 将字符串的 ArrayList 拆分为另一个字符串的 ArrayList,返回类型为 List,而不是 void

python - 在 Python 函数中返回多个列表

android - 如何取消选中删除 Android 中项目的复选框?

java - 如何在 Android Studio 中显示参数类型标签?

机器人 : how to start activity defined in library project

android - 从 SearchManager Activity 获取结果到 android 中的主要 Activity

java - 错误 : "requestFeature() must be called before adding content", 虽然它是在 setContentView() 之前调用的