【问题标题】:Is there any way to catch phone call answer event?有什么方法可以捕捉电话接听事件吗?
【发布时间】:2019-09-05 10:29:44
【问题描述】:

我试图捕捉电话接听事件,甚至可以使用 react-native 吗?
此时我正在使用https://github.com/priteshrnandgaonkar/react-native-call-detection。在通话开始时,我捕捉到了摘机事件,这很好,但我真的需要捕捉电话接听事件。
感谢所有帮助和提示。谢谢!

    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
}
},

【问题讨论】:

    标签: android ios react-native mobile phone-call


    【解决方案1】:

    这可能对你有帮助

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

    【讨论】:

    • 想多解释一下吗?没有真正回答问题
    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2011-05-21
    • 2020-06-20
    • 1970-01-01
    • 2012-02-03
    • 2021-04-08
    • 2012-08-14
    • 2011-08-21
    相关资源
    最近更新 更多