Tuesday 25 December 2012

Android phone call program.

This program helps you to call . Code used is very simple and easy to understand. This program uses phone call intent. Just create a on click method add the intent   Intent call Intent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123"));startActivity(callIntent); . This will trigger the call. To initiate the call add the phone number after tel:here___.

Code: (MainActivity)
package com.example.dialnumber;
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.widget.Button;
public class MainActivity extends Activity {
private Button buttonte1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonte1 = (Button)findViewById(R.id.button1);
buttonte1.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:123"));
startActivity(callIntent);
}});}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;}}
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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<Button
android:id="@+id/button1"
android:layout_width="500px"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="CustomerCare" />
</RelativeLayout>

No comments:

Post a Comment