【问题标题】:How to end outgoing call automatically in android java?如何在android java中自动结束拨出电话?
【发布时间】:2019-05-04 14:32:07
【问题描述】:

我有一个编辑文本,我在其中输入用户的电话号码并拨打电话,一旦电话响起,我想自动结束通话,而不是用户切断通话。我怎样才能以编程方式实现这一目标? 这是我的 MainActivityCode:

    phnum = edNumber.getText().toString();
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + phnum));


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    startActivity(callIntent);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }

清单:

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>

【问题讨论】:

    标签: android broadcastreceiver call phone-number outgoing-call


    【解决方案1】:

    要结束通话,请按以下步骤操作:

    1. 如果用户终止通话,则调用setDisconnected(DisconnectCause)发送LOCAL作为参数,如果对方终止通话,则发送REMOTE作为参数。
    2. 调用destroy() 方法。 了解更多请click here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多