05 July, 2010

Program to make a phone call in Android Phone

Android by default includes and application called PhoneApp, which actially includes the functions of mobile phone. Intent is an Android API wich actually communicates between different Anrdoid applications to perform certain operations such as initializing a phone call. To enable your application to initialize a phone call the following simple code will serve.
private void makecall()
{
try
{
Intent phonecallIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:9884179964"));
startActivity(phonecallIntent);
}
catch (ActivityNotFoundException activityException)
{
Log.e("makeCallDemo", "Call failed", activityException);
}
}
So, in the above example the instance of Intent class will actually search for the application which provides ACTION_CALL action in this case PhoneApp and tell the android system that we want to start a phone call. The startActivity method will actually initiate the phone call to the provided number. The phone number provided above should follow the E.164 Number format.

0 comments: