1

Why am I getting the incoming number twice? With the outgoing detail it is properly working, but it gets only once but I don't know what happens to incoming detail. Can anyone help me?

 public void onReceive(Context context, Intent intent) {

    Log.d("APP", "ACTION:" + intent.getAction());
    //this.context = context;
    final String stringExtra = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())){
        //outgoing call
        number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        Log.i("tag", "Outgoing number : " +number);
        currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
        Log.i("tag", "Date :" + currentDateTimeString);
       //doSaveCallRecord(1);
        Log.i("tag", "USER ID :" + context.getSharedPreferences("APPLICATION",Context.MODE_PRIVATE).getString(UserConstants.ID,null)+"");
    }
    if (TelephonyManager.EXTRA_STATE_RINGING.equals(stringExtra)) {
        final String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
        Log.d("APP", "incoming,ringing:" + incomingNumber);
        //doSaveCallRecord(0);
    }
}
<receiver android:name=".MyCallReceiver" > 
      <intent-filter> 
          <action android:name="android.intent.action.NEW_OUTGOING_CALL"/> 
          <action android:name="android.intent.action.PHONE_STATE"/> 
      </intent-filter>
</receiver>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pratik Sule
  • 163
  • 4
  • 18
  • please provide the code for sendBroadcast – Hari Krishnan Oct 16 '15 at 11:05
  • Please, post your AndroidManifest as well, as any Logcat (that logged a call for instance). Finally, try to describe an example condition that duplicates the desired and undesired effect. Also, the described event is likely two or more receivers with the same broadcast event. Show where you registered the receivers (dinamically and statically) – Bonatti Oct 16 '15 at 11:52

1 Answers1

0

Here is my code for checking incoming number to specific number:

 @Override
public void onReceive(final Context context, Intent intent) {
    TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(new PhoneStateListener() {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
            if(incomingNumber.contains("CHECKING NUMBER")){
                AudioManager audio_mngr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
                audio_mngr.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
            }
            System.out.println("incomingNumber : "+incomingNumber);
        }
    },PhoneStateListener.LISTEN_CALL_STATE);
}
piyush poriya
  • 316
  • 1
  • 3
  • 18