Android App Development With AndroidCource: android phone call.
Showing posts with label android phone call.. Show all posts
Showing posts with label android phone call.. Show all posts

Saturday, 30 June 2018

Android Phone Calls Example

Android provides Built-in applications for phone calls.How to make Phone Call in android Programmatically.It Can Use to Call Phone in android.

Intent Object Use to make Call in android.It can Use To ACTION_CALL action trigger to automatically phone call function call in android device available function.

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.

Add Permission in AndroidManifest.xml file

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

MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:hint="Enter Mobile No"
        android:inputType="phone"
        android:imeOptions="actionDone"
        android:maxLength="10"
        android:id="@+id/et_mobile"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_gravity="center_horizontal"
        android:id="@+id/btn_call"
        android:text="Call"/>
</LinearLayout>

MainActivity.java

package com.example.bhaumik.phonecall;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    EditText editText;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.et_mobile);
        button = findViewById(R.id.btn_call);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED){

                    return;
                }

                Intent intent = new Intent(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:"+ editText.getText().toString()));

                startActivity(intent);
            }
        });
    }
}
Android Phone Call Example

Ads