【问题标题】:How to make a call via dialer programmatically in android Pie and above如何在android Pie及更高版本中以编程方式通过拨号器拨打电话
【发布时间】:2020-02-23 08:13:38
【问题描述】:

我使用此代码显示号码,并在按下它进行拨号时使用它。它适用于 Android Pie 之前的 android 版本。

    final Button but= findViewById(R.id.buttond);
    but.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String PhNumber = "6998474783";////example number
            final CharSequence[] phones = PhNumber.split(" - ");
            AlertDialog.Builder builder = new AlertDialog.Builder(CTX);
            builder.setTitle("Επιλογή Τηλεφώνου");
            builder.setItems(phones, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    // Do something with the selection
                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phones[item].toString()));
                    if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {                           
                        return;                        }
                    startActivity(intent);                       
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    });

要使用 Pie 及更高版本,我必须进行哪些更改? 它显示了电话号码,但当我按下它时没有任何反应

【问题讨论】:

    标签: android-9.0-pie android-phone-call telecom-manager


    【解决方案1】:

    在没有任何 checkSelfPermission 的情况下使用 ACTION_DIAL 解决。

      Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phones[item].toString()));
        startActivity(intent); 
    

    如果有其他方法,请电信经理发一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多