Learn Python


Click to Learn Python3

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

7 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. The telephone is the best medium if you want to communicate with other people but it could also be used to harass other people. Dealing with free business calls harassment could be really scary and annoying. You should know what to do to put a stop to harassing phone calls and secure your privacy.

    ReplyDelete
  3. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    Php projects with source code
    Online examination system in php
    Student management system in php
    Php projects for students
    Free source code for academic
    Academic projects provider in nashik
    Academic project free download

    ReplyDelete