Phone Call
We are discussing how to make phone call in android
pro-grammatically. The simple steps create an application can be used phone
call. You can used android Intent to make phone call by calling built-in phone
call functionality of the android.
Intent-Object:- ACTION_CALL action call
built in android
Device functionality.
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
Show complete example:
package com.example.androidbignnerpopint;
import
android.app.Activity;
import
android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import
android.view.MenuItem;
import android.view.View;
import
android.widget.Button;
import
android.widget.RadioButton;
import
android.widget.RadioGroup;
import
android.widget.Toast;
public class MainActivity extends Activity {
Button b1;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);
call();
}
private void call() {
Intent in=new Intent(Intent.ACTION_CALL,Uri.parse("0000000000"));
try{
startActivity(in);
}
catch
(android.content.ActivityNotFoundException ex){
Toast.makeText(getApplicationContext(),"Not found
your Activity",Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
//
Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean
onOptionsItemSelected(MenuItem item) {
//
Handle action bar item clicks here. The action bar will
//
automatically handle clicks on the Home/Up button, so long
//
as you specify a parent activity in AndroidManifest.xml.
int id =
item.getItemId();
//noinspection
SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Androidbignnerpoint Phone Call Example"
android:id="@+id/textView"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="20dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:text="08976357623" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="132dp"
android:text="Call" />
</RelativeLayout>
But don’t
forget given permission in androidmanifest.xml class.
0 comments