I am trying to do some work at incoming call times. I am trying like this
public class callDeductor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
Toast.makeText(context, "Phone Is Ringing", Toast.LENGTH_LONG).show();
}
if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
Toast.makeText(context, "Call Recieved", Toast.LENGTH_LONG).show();
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
Toast.makeText(context, "Phone Is Idle", Toast.LENGTH_LONG).show();
}
}
}
This is my Manifeast:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.deduct.calldeduct"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="Call Deduct" >
<receiver android:name="com.deduct.calldeduct.callDeductor" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
I check with mobile and emulator. But it does not show any toast message. Please let me know where I did mistake.