Technical Knowledge

technical knowledge is that type of blogger in which you can find all the soluctions of your problems which you cannot solve you can see the video given on this blog and solve your problem by yourself.

Like us on Facebook

Technical Knowledge

Sunday, March 29, 2015

How to make phone call from android program: Android tutorial

Program description:

This is a demo program on how to make a phone call from an android application on button click.

For this we will use ACTION_CALL in the intent, and pass the the Uri which contains phone number to make the call. On clicking the button it will launch the call application.

Note : It requires android permission "android.permission.CALL_PHONE".

First activity


package com.techpalle.b15_call;

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;

public class MainActivity extends Activity {
Button b;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent in = new Intent();
in.setAction(Intent.ACTION_CALL);
Uri myUri = Uri.parse("tel:12345");
in.setData(myUri);
startActivity(in);
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}
xml file for first activity 
File name : activity_main.xml
  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" >

Download complete code : Click to download

Tags: android, make phone call

No comments:

Post a Comment