Pages

About

Pages - Menu

Ads 468x60px

Social Icons

Main Menu

Featured Posts

Friday 4 July 2014

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.


0 comments:

Post a Comment

Followers