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.getText().toString();
btnPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
call();
}
});
public void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(phone));
startActivity(callIntent);
} catch (ActivityNotFoundException activityException) {
Log.e("myphone dialer", "Call failed", e);
}
}
I added all permissions
to manifest file.
but I am getting NullPointerexception
Intent Object - Action to make Phone CallIntent phoneIntent = new Intent(Intent. ACTION_CALL); You can use ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to modify hardcoded phone number before making a call instead of making a direct call.
An Intent object carries information that the Android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the ...
The intent is a messaging object which passes between components like services, content providers, activities, etc. Normally startActivity() method is used for invoking any activity. Some of the general functions of intent are: Start service.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With