Call Finder Demo In Android Programming

This application registers for incoming and outgoing actions and when the calls are detected it just displays a toast.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it CallFinderDemo.

2.) Write following into main.xml:

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a simple application to demonstrate how to detect incoming and outgoing calls.nnWhen an incoming and outgoing call is detected, this application just display a Toast."/>
</LinearLayout>

 

 

3.) Create and write following into src/receivers/OutgoingCallReceiver.java:

 

package com.example.callfinderdemo.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class OutgoingCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if(null == bundle)
return;

String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

Log.i("OutgoingCallReceiver",phonenumber);
Log.i("OutgoingCallReceiver",bundle.toString());

String info = "Detect Calls sample applicationnOutgoing number: " + phonenumber;

Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}

 

 

4.) Create and write following into srcr/eceivers/IncomingCallReceiver.java:

 

package com.example.callfinderdemo.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class IncomingCallReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if(null == bundle)
return;

Log.i("IncomingCallReceiver",bundle.toString());

String state = bundle.getString(TelephonyManager.EXTRA_STATE);

Log.i("IncomingCallReceiver","State: "+ state);

if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);

String info = "Detect Calls sample applicationnIncoming number: " + phonenumber;

Toast.makeText(context, info, Toast.LENGTH_LONG).show();
}
}
}

 

 

5.) Write following into the manifest file:

 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callfinderdemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".CallFinderDemoActivity"
android:label="@string/title_activity_call_finder_demo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".receivers.OutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>

<receiver android:name=".receivers.IncomingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
</manifest>

 

 

6.) Run for output.

Steps:

1.) Create a project named CallFinderDemo and set the information as stated in the image.

Build Target: Android 4.0
Application Name: CallFinderDemo
Package Name: com. example. CallFinderDemo
Activity Name: CallFinderDemoActivity
Min SDK Version: 2.2

2.) Open CallFinderDemoActivity.java file and write following code there:

 

package com.example.callfinderdemo;

import android.app.Activity;
import android.os.Bundle;

public class CallFinderDemoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

 

 

3.) Compile and build the project.

Note: – For better results check on device.

Output

Leave a Comment:

1 comment
mesothelioma cancer says July 13, 2013

whoah this weblog is wonderful i really like reading your articles. Keep up the great work! You already know, many people are looking round for this info, you can help them greatly.

Reply
Add Your Reply