1

我已经搜索了两天,但没有找到

是否可以通过编程方式检测拨出电话的状态(已接听、占线或掉线)?谢谢您的回答。

4

1 回答 1

0
*// Add receiver to manifest file

public class OutgoingCallReceiver extends BroadcastReceiver {
    private static long timeStarted = -1L; // IMPORTANT!

    private static String number;
    private static boolean noCallListenerYet = true;

    @Override
    public void onReceive(final Context context, Intent intent) {
        PhoneCallListener phoneListener = new PhoneCallListener(context);
        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener,
                PhoneStateListener.LISTEN_CALL_STATE);
    }

    private class PhoneCallListener extends PhoneStateListener {
        Context context;
        private boolean isPhoneCalling = false;

        public PhoneCallListener(Context context2) {
            // TODO Auto-generated constructor stub
            context=context2;
        }

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
            //do something here
            }

            if (state == TelephonyManager.CALL_STATE_IDLE && timeStarted != -1L) {}
        }
    }
}
于 2013-02-21T11:35:17.620 回答