Android Project

Android Project
Android Project

Monday, March 14, 2011

Make a phone call using Android code in application?

We can write code to make a call from the android application that we created.

The below code is enough to make a call from the application,


Java

Intent sIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:919894643826"));
startActivity(sIntent);


We can put this code in a click event, so that on clicking a button or textview the call be done.

Likewise we need to add this line inside the Manifest.xml file


XML

<uses-permission android:name="android.permission.CALL_PHONE"></uses>


The java code will be like this

Caller.java

package com.phone.calller;

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

public class Callers extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Phone = (Button) findViewById(R.id.call);
Phone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sIntent = new Intent(Intent.ACTION_CALL, Uri
.parse("tel:919894643826"));
startActivity(sIntent);
}
});
}
}


and the manifest.xml file will be like this


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.phone.calller"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Callers"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-permission android:name="android.permission.CALL_PHONE" />

</manifest>

Have a good day.

The full source code

Download source

6 comments:

  1. Google is one of the popular search Engine.Google is playing an Important role In internet marketing field.
    Android app developers

    ReplyDelete
  2. It's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving... very specific nice content.Android Training institute in chennai with placement | Android Training in chennai |Best Android Training in Velachery | android development course fees in chennai

    ReplyDelete
  3. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Android Training in chennai | Android Training|Android Training in chennai with placement | Android Training in velachery

    ReplyDelete

Sponser