I use descendant - class of PhoneStateListener:
class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
if (incomingNumber!=null)
{
// code for incoming call handling
}
break;
}
super.onCallStateChanged(state, incomingNumber);
}
this is my BroadcastReceiver:
class ServiceReceiver extends BroadcastReceiver {
CallStateListener phoneListener;
@Override
public void onReceive(final Context context, Intent intent) {
if (phoneListener == null) {
phoneListener = CallStateListener.getCallStateInstance(context);
TelephonyManagerSingletone.getInstance().getTelephonyManager().listen(CallStateListener.getCallStateInstance(context),
android.telephony.PhoneStateListener.LISTEN_CALL_STATE);
}
}
manifest:
<receiver android:name="com.library.ServiceReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
but when I use it like this, I receive duplicate call in my CallStateListener. How can I fix this?