Call intent in Android

前端 未结 7 1221
生来不讨喜
生来不讨喜 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:50

    This simple approach should work for you.

    Ex.

    public class CallActivity extends Activity{
       String phone = "";
    
       onCreate()
       {
            btnPhone.setOnClickListener(new View.OnClickListener() { 
                @Override 
                public void onClick(View arg0) { 
                    phone = editPhone.getText().toString(); 
                    call(); 
                } 
            });    
       }
    
       public void call() {   
                Intent callIntent = new Intent(Intent.ACTION_CALL);          
                callIntent.setData(Uri.parse("tel:"+phone));          
                startActivity(callIntent);  
       }
    }
    

    You might be using String variable phone out of scope.

提交回复
热议问题