首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法捕捉电话应答事件?

有没有办法捕捉电话应答事件?
EN

Stack Overflow用户
提问于 2019-09-05 18:29:45
回答 1查看 983关注 0票数 0

我尝试捕获电话呼叫应答事件,是否可以使用react-native?

现在我使用的是https://github.com/priteshrnandgaonkar/react-native-call-detection。在呼叫开始时,我捕获了摘机事件,这很好,但我真的需要捕获电话应答事件。

感谢所有的帮助和提示。谢谢!

代码语言:javascript
复制
    startListenerTapped() {
this.callDetector = new CallDetectorManager((event)=> {
// For iOS event will be either "Connected",
// "Disconnected","Dialing" and "Incoming"

// For Android event will be either "Offhook",
// "Disconnected", "Incoming" or "Missed"


if (event === 'Disconnected') {
// Do something call got disconnected
} 
else if (event === 'Connected') {
// Do something call got connected
// This clause will only be executed for iOS
} 
else if (event === 'Incoming') {
// Do something call got incoming
}
else if (event === 'Dialing') {
// Do something call got dialing
// This clause will only be executed for iOS
} 
else if (event === 'Offhook') {
//Device call state: Off-hook. 
// At least one call exists that is dialing,
// active, or on hold, 
// and no calls are ringing or waiting.
// This clause will only be executed for Android
}
else if (event === 'Missed') {
    // Do something call got missed
    // This clause will only be executed for Android
}
},
EN

回答 1

Stack Overflow用户

发布于 2019-09-05 18:37:28

这可能会对你有帮助

代码语言:javascript
复制
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.content.SharedPreferences;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;

    public class CallHelper {
        private Context context;
        private TelephonyManager tm;
        private CallStateListener callStateListener;

        private OutgoingReceiver outgoingReceiver;

        SharedPreferences prefs;
        public static final int MODE_MULTI_PROCESS = 4;

        public CallHelper(Context ctx) {
            this.context = ctx;
            callStateListener = new CallStateListener(ctx);
            outgoingReceiver = new OutgoingReceiver();
        }

        /**
         * Listener to detect incoming calls.
         */
        private class CallStateListener extends PhoneStateListener {
            public CallStateListener(Context con) {
                OnLed = new Flasher(con);
            }

            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                switch (state) {
                case 1:

                    break;
                case 2:

                    break;
                case 0:

                    break;
                }
                super.onCallStateChanged(state, incomingNumber);
            }
        }

        /**
         * Broadcast receiver to detect the outgoing calls.
         */
        public class OutgoingReceiver extends BroadcastReceiver {
            public OutgoingReceiver() {
            }

            @Override
            public void onReceive(Context context, Intent intent) {
                // call listening

            }

        }

        /**
         * Start calls detection.
         */
        public void start() {
            tm = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

            IntentFilter intentFilter = new IntentFilter(
                    "android.provider.Telephony.SMS_RECEIVED");
            context.registerReceiver(outgoingReceiver, intentFilter);
        }

        /**
         * Stop calls detection.
         */
        public void stop() {
            tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
            context.unregisterReceiver(outgoingReceiver);
        }

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57803456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档