簡體   English   中英

如何在android studio中的ACTION_CALL中使用2個字符串

[英]How to use 2 Strings in ACTION_CALL in android studio

我編寫了此代碼以使用我的應用程序呼叫一個號碼,但是我應該使用兩個字符串將這兩個數字連接起來並進行呼叫。

實際的數字是這樣的(* 123 *電話號碼* EditText#中的數字)我應該使用2個字符串來具有這樣的代碼(* 123 *電話號碼* String2 + String1)

Strin1 =#,但是使用此代碼按鈕無效。

如何用2個字符串調用?

Java代碼如下:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);

    this.btnCall = ((Button) findViewById(R.id.btn_call));
    this.money = ((EditText) findViewById(R.id.edittextsend));

    btnCall = (Button) findViewById(R.id.btn_send);
    btnCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(ACTION_CALL);
            String str2 = money.getText().toString();
            Object object;
            try {
                String str1 = URLEncoder.encode("#", "UTF-8");
                object = str1;
            } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
                for (;;) {
                    localUnsupportedEncodingException.printStackTrace();
                }
            }
            i.setData(Uri.parse("tel:" + "*123*0794100163*" + str2 + object));

            if (PackageManager.PERMISSION_GRANTED != ActivityCompat.checkSelfPermission(About.this, Manifest.permission.CALL_PHONE)) {
                // 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(i);
        }

    });
}

您不能使用電話號碼字符串中的“#”或“ *”來撥打電話。 改用Intent.ACTION_DIAL

String dialString = "*100*9819283913*123123#";
Intent i = new Intent (Intent.ACTION_DIAL, Uri.parse ("tel:" + Uri.encode (dialString)));
startActivity (i);

無需在清單文件中檢查android.permission.CALL_PHONE的權限

輸出:
在此處輸入圖片說明

謝謝gyes的出色回答,也很抱歉重播。 最后,我找到了我的答案,它將通過電話呼叫。 代碼如下所示:

如果(ActivityCompat.checkSelfPermission(MonySendActivity.this,Manifest.permission.CALL_PHONE)!= PackageManager.PERMISSION_GRANTED){

        ActivityCompat.requestPermissions(MonySendActivity.this, new String[] { "android.permission.CALL_PHONE" }, 1);

        String str2 = roshanmoney.getText().toString();
        String str3 = roshannumber.getText().toString();
        String objectmoney;
        try {
            String str1 = URLEncoder.encode("#", "UTF-8");
            objectmoney = str1;
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            for (;;) {
                localUnsupportedEncodingException.printStackTrace();
            }
        }

        Intent i = new Intent(ACTION_CALL, Uri.parse("tel:*123*07" + str3 + "*" + str2 + objectmoney));
        startActivity(i);
        return ;
    }else {
        String str2 = roshanmoney.getText().toString();
        String str3 = roshannumber.getText().toString();
        String object;
        try {
            String str1 = URLEncoder.encode("#", "UTF-8");
            object = str1;
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            for (;;) {
                localUnsupportedEncodingException.printStackTrace();
            }
        }

        Intent i = new Intent(ACTION_CALL, Uri.parse("tel:*123*07"+ str3 + "*" + str2 + object));
        startActivity(i);

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM