Android BroadCastReciever Example
When an event happens if users need intimation we can use Broadcast Receiver.Event like incoming/outgoing calls.
You can download source code here.
Create another class to extend BroadcastReciever.
You can download source code here.
Following steps:-
Add Receiver and Permission from android manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.etr.broadcastreceiverexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.etr.broadcastreceiverexample.BroadCastActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".ReceiverHandler" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
</manifest>
Create another class to extend BroadcastReciever.
package com.etr.broadcastreceiverexample;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class ReceiverHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
Toast.makeText(context, "OutGoing call is progress",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("ReceiverHandler Exception", Log.getStackTraceString(e));
}
}
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class ReceiverHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
Toast.makeText(context, "OutGoing call is progress",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e("ReceiverHandler Exception", Log.getStackTraceString(e));
}
}
}
Comments
Post a Comment