Broadcast Receiver Doesn't Subtract Calls - Android

I am trying to do some work during incoming calls. I try so hard

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 the mobile and emulator. But there are no toasts in it. Please let me know where I was wrong.

I got a link from these sites. Link 1 Link 2

0
source share
1 answer

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(); } } } 

ScreenShot of the project set up:

+1
source

All Articles