0

I use this code to show the number and when pressing it to make a dial.It is working for android versions before Android Pie.

    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();
        }
    });

What I have to change to work with Pie and above? It shows the phone number but when I press it nothing happens

4

1 回答 1

0

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

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

如果有任何其他方式,也许与电信经理请发布。

于 2019-10-28T00:46:21.187 回答