Sumit
Sumit

Reputation: 928

making phone call in android

Making a Call through android device via phone and the code does not seems to work

I am call this function

private void call() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("912345678"));
        startActivity(callIntent);
    } catch (ActivityNotFoundException activityException) {
        Log.e("dialing-example", "Call failed", activityException);
    }
}

also I have given the permission

<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>

What am I doing wrong any one can guide me?

Upvotes: 1

Views: 404

Answers (2)

user1292458
user1292458

Reputation:

 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
                       startActivity(intent);      

make permission in manifest file:

 <uses-permission android:name="android.permission.CALL_PHONE"/>

Upvotes: 4

Anirudh Ramanathan
Anirudh Ramanathan

Reputation: 46728

callIntent.setData(Uri.parse("tel:91234566"));

If you do not specify the scheme of the URI (tel: in this case), it won't be recognized as a phone number and hence, the desired action will not occur.

Upvotes: 2

Related Questions