Continuing my conversation with the respondent as an answer. I just started a new Android app and developed, as I said in the comments. the manifest is as follows:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.dj.randomtest" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="19" /> <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" > <receiver android:name=".CallDetector"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver> <activity android:name=".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>
The CallDetector class looks like this (ur code):
public class CallDetector 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(); } } }

source share