Friday, April 27, 2012

How to Make a Phone Call Programmatically in Android

 -------------------------------------------
App Name: MakeACall
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: MyActivity
-------------------------------------------


MyActivity.java


package com.rdc;

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;

public class MyActivity extends Activity implements OnClickListener {

 private Button btncall = null;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

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

 @Override
 public void onClick(View v) {
  String mobileNo = "+919741817902";
  String uri = "tel:" + mobileNo.trim();
  Intent intent = new Intent(Intent.ACTION_CALL);
  intent.setData(Uri.parse(uri));
  startActivity(intent);
 }
}

main.xml

 


AndroidManifest.xml

 





 
 
 
 





The output Screen will be like this..


You can download the complete source code zip file here : MakeACall

 cheers!!

 I'd love to hear your thoughts!

No comments:

Post a Comment