How to make a phone call from your Android app

If you want to make a phone call from android app, write below code when you want to call on any number:

Intent dialIntent = new Intent();
dialIntent.setAction(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel:9494299494"));


If you want to call on dynamic number:

String number = "9494942994";
Intent dialIntent = new Intent();
dialIntent.setAction(Intent.ACTION_DIAL);
dialIntent.setData(Uri.parse("tel:"+number));


 Intent.ACTION_DIAL brings up the dialer, but doesn't actually make the phone call. For make directly phone call, replace action as below:

dialIntent.setAction(Intent.ACTION_CALL);

You'll also have to declare android.permission.PHONE_CALL permission in your AndroidManifest.xml and above Android 6 (Marshmallow), give run-time permission. For run-time permission in android, I suggest  to use TedPermission library. TedPermission is a simple permission check helper.

Comments

Popular posts from this blog

SQLiteDatabase (Without SqliteOpenHelper class)

Set current date to Button and Datepicker dialog

MVC Architecture in Android