Phone Call Tutorial:
In this tutorial we are discussing about how phone call operate in the Android.

1.Simply Copy and Past the Code which is display below in the MainActivity.java
In this tutorial we are discussing about how phone call operate in the Android.
OUT PUT Of The Tutorial:
Create Android Application:
- File >> New >> Android Application
- Enter Project name: PhoneCallApp
- Package: com.ambilpursunil.newapp
- Keep other default selections, click Next until you reach Finish

1.Simply Copy and Past the Code which is display below in the MainActivity.java
package com.ambilpursunil.newapp;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button callButton = (Button)
findViewById(R.id.bCall);
callButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
makeCall();
}
});
}
private void makeCall() {
// TODO Auto-generated method stub
Log.i("MakeCall","
");
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:91-9177-000-000"));
try{
startActivity(callIntent);
finish();
Log.i("Finished
Calling..","");
}catch(android.content.ActivityNotFoundException
ex){
Toast.makeText(MainActivity.this, "Call
Failed,Please Try Again Later", 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.main, menu);
return true;
}
}
2.Simple Copy and Past the below code: actvitiy_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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/bCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:textSize="20dp"
android:textColor="#00FF00"
android:text="@string/make_call" />
</RelativeLayout>
3.Copy and past the code for manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ambilpursunil.newapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17"
/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ambilpursunil.newapp.MainActivity"
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>
</manifest>
When our application launch click on the Calling Button Then it will redirected to our predefined phone call option of our mobile and automatically phone call will arrive to the given number.
Stay Tune For Next Tutorial... Sending SMS In Android:
No comments:
Post a Comment