How to Create a Calling Application in Android

This blog defines code to create a calling Application in Android. 

MainActivity.java
 
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity
{
     EditText et;
     Button call_btn;
    @Override
     protected void onCreate(Bundle savedInstanceState)
     {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        et=(EditText)findViewById(R.id.editText1);
        call_btn=(Button)findViewById(R.id.button1);
        call_btn.setOnClickListener(new OnClickListener()
       {                                               
               @Override
               public void onClick(View v)
              {
                   // TODO Auto-generated method stub
                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.parse("tel:"+et.getText().toString()));
                    startActivity(i);
               }
         });
     }
}
 
 Code -activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  
xmlns:tools="http://schemas.android.com/tools"
  
android:layout_width="match_parent"
  
android:layout_height="match_parent"
  
android:paddingBottom="@dimen/activity_vertical_margin"
  
android:paddingLeft="@dimen/activity_horizontal_margin"
  
android:paddingRight="@dimen/activity_horizontal_margin"
  
android:paddingTop="@dimen/activity_vertical_margin"
  
tools:context=".MainActivity" >
      <TextView

          
android:id="@+id/textView1"
       
    android:layout_width="wrap_content"
       
    android:layout_height="wrap_content"
       
    android:text="Dial No." />
      <Button

          
android:id="@+id/button1"
          
android:layout_width="wrap_content"
       
     android:layout_height="wrap_content"
          
android:layout_alignLeft="@+id/textView1"
       
     android:layout_below="@+id/textView1"
          
android:layout_marginLeft="44dp"
       
    android:layout_marginTop="84dp"
       
    android:text="Call" />
      <EditText

       
    android:id="@+id/editText1"
       
    android:layout_width="wrap_content"
       
    android:layout_height="wrap_content"
       
    android:layout_alignLeft="@+id/textView1"
       
    android:layout_below="@+id/textView1"
       
    android:layout_marginLeft="18dp"
       
    android:ems="10" >
        <requestFocus />       

  </
EditText>
</
RelativeLayout> 

Note - We have to add permission  android.permission.CALL_PHONE in android manifest file.


 
Output
 
 
 
 
   
 
 
 ENJOY YOUR OWN CUSTOM CALLING APP...... :)
Ebook Download
View all
Learn
View all