简体   繁体   English

如何拨号

[英]How to dial a number

I am trying to dial a number like *123*0xxxxxxxxxx# . 我想拨打* 123 * 0xxxxxxxxxx#这样的号码。 And the 0xxxxxxxxxx portion would be got from the user input through an edit text.my code is here 并且0xxxxxxxxxx部分将通过编辑文本从用户输入获得。我的代码在这里

EditText et1;
String ET1;
String pnd,encode_zero;
Button call;

Intent callIntent = new Intent(Intent.ACTION_CALL);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.call);

    et1 = (EditText) findViewById(R.id.et1);
    call = (Button) findViewById(R.id.btn_call);

    ET1 = et1.getText().toString();
call.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
                  pnd = Uri.encode("#");
          encode_zero = Uri.encode("0");
                  callIntent.setData(Uri.parse("tel:*123*0" + ET1 + pnd));
                  startActivity(callIntent);

      }
  });

but when I run the app it ends with telling invalid number . 但是当我运行应用程序时,它会告诉无效的号码。 that means I think the zero(0) is not considered. 这意味着我认为不考虑零(0)。 I have tried with this one too... 我也尝试过这个......

public void onClick(View v) {
                  pnd = Uri.encode("#");
          encode_zero = Uri.encode("0");
                  callIntent.setData(Uri.parse("tel:*123*" + encode_zero + ET1 + pnd));
                  startActivity(callIntent);

      }

but the result is all the same. 但结果都是一样的。 Now what can I do ? 现在我该怎么办?

确保将此权限添加到清单

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

This code opens the phone dialer with the number on it - 此代码打开带有号码的电话拨号器 -

        String number = "*123*0123456#";
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:" + Uri.encode(number)));
        if (ActivityCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

            return;
        }
        startActivity(callIntent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM