Reputation: 515
We know you can open a call application using this code:
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0377778888")));
Is it possible to make a direct call without having to go through the default application of the device?
Upvotes: 1
Views: 1233
Reputation: 101
Yes, You can do it by just replacing Intent.ACTION_DIAL
with Intent.ACTION_CALL
in your code.
And you must need the CALL permission to the app.
For below Marshmallow devices you can make it by simply placing the below line in your manifest under manifest tag
<uses-permission android:name="android.permission.CALL_PHONE" />
.
But for Marshmallow or above OS devices you need to declare the permission in manifest like below
<uses-permission-sdk-23 android:name="android.permission.CALL_PHONE" />
And you need to ask the user Runtime permission for CALL_PHONE access. To request permission
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.CALL_PHPNE})
To check permission
ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED
For more info https://developer.android.com/training/permissions/requesting.html
Upvotes: 2
Reputation: 7391
This code snippet makes the direct call:
// Check the SDK version and whether the permission is already granted or not.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, PERMISSIONS_REQUEST_PHONE_CALL);
} else {
//Open call function
String phone = "7769942159";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:+91" + phone));
startActivity(intent);
}
Use this permission in manifest:
<uses-permission android:name="android.permission.CALL_PHONE" />
Upvotes: 4
Reputation: 13153
Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phno);
startActivity(intent);
Android Manifest
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
Upvotes: 1
Reputation: 75619
You are looking for ACTION_CALL
: https://developer.android.com/reference/android/content/Intent.html
Upvotes: 1