Opening phone dialer from an Android application

June 24, 2012
By

Phone dialer is an activity available with Android operating system to call a number. In this article, we will create an application which invokes the dialer on a button click.  Android system provides a standard action name called “ACTION_DIAL” to invoke the dialer. We will make use this action to invoke the the dialer from our application.


1. Create a new Android project namely “DialerDemo”

New Android Project

Figure 1 : New Android Project


2. Select build target for the application

Android Build Target

Figure 2: Android Build Target


 

3. Enter application details

Application Details

Figure 3: Application Details


4. res/values/strings.xml


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, MainActivity!</string>
    <string name="app_name">DialerDemo</string>
    <string name="dialer">Open Dialer</string>
</resources>


5. res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

<Button
    android:id="@+id/btn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/dialer" />

</LinearLayout>


6. src/in/wptrafficanalyzer/dialerdemo/MainActivity.java

package in.wptrafficanalyzer.dialerdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /** Referring to the button object of the main.xml layout */
        Button btn  = (Button) findViewById(R.id.btn);

        /**    Defining a click event listener    */
        OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                /** Creating an intent with the dialer's action name  */
                /** Since the intent is created with activity's action name, the intent is an implicit intent */
                Intent intent = new Intent("android.intent.action.DIAL");

                /** Starting the Dialer activity */
                startActivity(intent);
            }
        };

        /** Setting click event listener for the buttonS */
        btn.setOnClickListener(listener);
    }
}


 %MINIFYHTML2984bb057e7b4189f2849a82ef1dc8ca9%
%MINIFYHTML2984bb057e7b4189f2849a82ef1dc8ca10%7. Application in execution
Main Activity

Figure 4: Main Activity

  • On clicking the button "Open Dialer", the given below "Phone Dialer" will be opened"
Dialer Activity

Figure 5: Dialer Activity


8. Download


9. Reference

http://developer.android.com/guide/index.html


How to hire me?

I am George Mathew, working as software architect and Android app developer at wptrafficanalyzer.in

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to info@wptrafficanalyzer.in.

My other blogs
store4js.blogspot.com


Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :



Tags: , ,

One Response to Opening phone dialer from an Android application

  1. abhinav aggarwal on August 22, 2014 at 11:19 pm

    i want to know that how to pass contact no also to the dialer .
    not just open but also to pass the number

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner