我试着接听电话接听事件,甚至可以使用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
}
},

最佳答案

这可能对您有帮助

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

    }

09-28 01:03