【问题标题】:When I press the call button my code does not make the phone call当我按下通话按钮时,我的代码无法拨打电话
【发布时间】:2017-11-21 14:30:59
【问题描述】:

请帮我修复我的代码,以便当我按下呼叫按钮时,代码会呼叫我提供的手机号码。

//monitor phone call activities
private class PhoneCallListener extends PhoneStateListener {

    private boolean isPhoneCalling = false;

    String LOG_TAG = "LOGGING 123";

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            isPhoneCalling = true;
        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(LOG_TAG, "OFFHOOK");
            isPhoneCalling = true;
        }

        if (TelephonyManager.CALL_STATE_IDLE == state) {
            // run when class initial and phone call ended,
            // need detect flag from CALL_STATE_OFFHOOK
            Log.i(LOG_TAG, "IDLE");

            if (isPhoneCalling) {
                Log.i(LOG_TAG, "restart app");

                // restart app
                Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                                getBaseContext().getPackageName());
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);

                isPhoneCalling = true;
            }

        }
    }
}

【问题讨论】:

    标签: javascript java android xml android-layout


    【解决方案1】:

    为了编写代码,您应该编写简单而小的代码,而不是调用给定号码的准确代码如下:

    // add button listener
            button.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
    
                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:"+999999999));//change the number  
                    startActivity(callIntent);
    
                }
    
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 2016-05-07
      • 1970-01-01
      相关资源
      最近更新 更多