I am trying to use the Intent.Action class. I know how to use the ACTION_VIEW to display a URL but I wanted to use the Intent.ACTION_DIAL to call number when th
For ACTION_DIAL you just need to create Intent object with that action as a first argument and Uri object as a second argument built from phone number written as a string. After that just call startActivity() method and pass previously created intent object as an argument. For example:
private String phoneNumber = "123456";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button dial_number = findViewById(R.id.button);
dial_number.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
startActivity(intent);
}
});
}