Reputation: 11829
Is there a way to call a contact without showing a UI that allows the user to initiate a call? So when I click on a button, the contact number is immediately dialed like when I go to the last calls in my phone an click on someone, they are immediately called.
The code I am using right now is:
try {
Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
} catch (Exception e) {
Log.e("SampleApp", "Failed to invoke call", e);
}
Upvotes: 4
Views: 1305
Reputation: 902
Intent intent = new Intent(Intent.CALL_ACTION);
should be
Intent intent = new Intent(Intent.ACTION_CALL);
This is my complete code:
Intent intentcall = new Intent();
intentcall.setAction(Intent.ACTION_CALL);
intentcall.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intentcall);
Upvotes: 0
Reputation: 3160
Add a permission android.permission.CALL_PHONE
to the manifest and change Intent.CALL_ACTION
to Intent.ACTION_CALL
Upvotes: 4
Reputation: 12636
Code you are posted should not work... there is no CALL_ACTION, use ACTION_CALL instead.
Upvotes: 2
Reputation: 9023
private void call() {
try {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123456789"));
startActivity(callIntent);
} catch (ActivityNotFoundException e) {
Log.e("helloandroid dialing example", "Call failed", e);
}
AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Upvotes: 1