Call intent in Android

前端 未结 7 1260
生来不讨喜
生来不讨喜 2020-12-10 06:16

How can I make call by pressing button? I get my number as a string from EditText. Here is my sample code:

String phone = editPhone         


        
7条回答
  •  感情败类
    2020-12-10 06:36

    I think you missed the "tel:" part in the URI.

    Replace the following..

    Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse(phone));
            startActivity(callIntent);
    

    with

    Intent callIntent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phone));
           startActivity(callIntent);
    

    or

    Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:"+phone));
                startActivity(callIntent);
    

提交回复
热议问题