Monday, June 17, 2013

Dial Number In Android Phone

Hi Guys!
Today I am sharing the code for dial a number to call any guys from android device.
In this article we will create an application which can call a telephone number directly from the application. In order to call a number we will make use the standard action called ACTION_CALL. An application can  call a number directly if  and only if  the necessary permission is explicitly granted. For this we need to provide CALL_PHONE permission to the application.

Main.xml






MainActivity.java

package com.sunil.call;


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

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

Button btn = (Button) findViewById(R.id.btnCall);
btn.setOnClickListener(this);

}

@Override
public void onClick(View v) {

EditText telNo = (EditText) findViewById(R.id.telNo);
String strTelNo = telNo.getText().toString();
Intent intent = new Intent("android.intent.action.CALL");

Uri data = Uri.parse("tel:"+ strTelNo );

intent.setData(data);
startActivity(intent);

}
}

Menifest.xml



















Cheers Guys!

Rocky

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

0 comments:

Post a Comment

 

Copyright @ 2013 Android Developers Tipss.