如何拨打电话在Android和回到我的活动通话时做了什么? [英] How to make a phone call in android and come back to my activity when the call is done?

查看:165
本文介绍了如何拨打电话在Android和回到我的活动通话时做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发起一项活动,打个电话,但是当我pressed了结束通话按钮,它不会再回到我的活动。你能告诉我怎样才能启动这又回到我结束通话当一个呼叫活动按钮是pressed?这就是我正在做的电话:

 字符串URL =电话:3334444;
    意向意图=新的意图(Intent.ACTION_CALL,Uri.parse(URL));
 

解决方案

使用PhoneStateListener看到通话结束的时候。你很可能需要触发听者行动等待调用启动(等到从PHONE_STATE_OFFHOOK改变再次PHONE_STATE_IDLE),然后写一些code,使您的应用程序备份在空闲状态。

您可能需要在服务运行的监听器,以确保它保持了和你的应用程序重新启动。一些例如code:

  EndCallListener callListener =新EndCallListener();
TelephonyManager MTM =(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener,PhoneStateListener.LISTEN_CALL_STATE);
 

监听器的定义:

 私有类EndCallListener扩展PhoneStateListener {
    @覆盖
    公共无效onCallStateChanged(INT状态,串incomingNumber){
        如果(TelephonyManager.CALL_STATE_RINGING ==州){
            Log.i(LOG_TAG,振铃,号码:+ incomingNumber);
        }
        如果(TelephonyManager.CALL_STATE_OFFHOOK ==州){
            //等待电话去摘机(可能设置一个布尔标志),让您知道您的应用程序发起呼叫。
            Log.i(LOG_TAG,摘机);
        }
        如果(TelephonyManager.CALL_STATE_IDLE ==州){
            //出现这种状态时,你的标志设置,重新启动您的应用程序
            Log.i(LOG_TAG空转);
        }
    }
}
 

在你的的Manifest.xml 文件中添加以下权限:

 <使用-权限的Andr​​oid:名称=android.permission.READ_PHONE_STATE/>
 

I am launching an activity to make a phone call, but when I pressed the 'end call' button, it does not go back to my activity. Can you please tell me how can I launch a call activity which comes back to me when 'End call' button is pressed? This is how I'm making the phone call:

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

解决方案

use a PhoneStateListener to see when the call is ended. you will most likely need to trigger the listener actions to wait for a the call to start (wait until changed from PHONE_STATE_OFFHOOK to PHONE_STATE_IDLE again) and then write some code to bring your app back up on the IDLE state.

you may need to run the listener in a service to ensure it stays up and your app is restarted. some example code:

EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

Listener definition:

private class EndCallListener extends PhoneStateListener {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        if(TelephonyManager.CALL_STATE_RINGING == state) {
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
        }
        if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
            //wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
            Log.i(LOG_TAG, "OFFHOOK");
        }
        if(TelephonyManager.CALL_STATE_IDLE == state) {
            //when this state occurs, and your flag is set, restart your app
            Log.i(LOG_TAG, "IDLE");
        }
    }
}

In your Manifest.xml file add the following permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

这篇关于如何拨打电话在Android和回到我的活动通话时做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆