Ring on silent mode
<p>I am writing an app which will ring on silent mode for certain numbers. I've created a broadcast listener which will listen to the incoming call and ring for a specific number.  The problem I'm facing is for the first time after installation it's not working and after that it's working perfectly.</p>

<p>The code I'm using is</p>

<pre><code>    public class Ring extends BroadcastReceiver{
private Context context;
private String PhoneNumber;
private int ringerMode=0;
String state=null;
Bundle bundle=null;

@Override
public void onReceive(Context context, Intent intent) {
 AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
  bundle = intent.getExtras();
  this.context = context;

  if(null == bundle)
          return;

  state = bundle.getString(TelephonyManager.EXTRA_STATE);

  if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
  {
          check();
          PhoneNumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
          if(PhoneNumber.equals("+918281306132"))
          makeitNormal();
          maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
  }
  if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK))
  {
      makeItSilent();
  }

  if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE))
  {
      makeItSilent();
  }
}

private void check() {
  // TODO Auto-generated method stub
  AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
  ringerMode=maudio.getRingerMode();

}

 private void makeitNormal() {
 // TODO Auto-generated method stub

   AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
   maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
 }


 private void makeItSilent() {
 // TODO Auto-generated method stub
 AudioManager maudio=(AudioManager)context.getSystemService(context.AUDIO_SERVICE);
  int ringer=maudio.getRingerMode();
  if (ringerMode==AudioManager.RINGER_MODE_SILENT){

  maudio.setRingerMode(AudioManager.RINGER_MODE_SILENT);

  }else if(ringerMode==AudioManager.RINGER_MODE_NORMAL){
  maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
 }
 else if(ringerMode==AudioManager.RINGER_MODE_VIBRATE){
  maudio.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
 }

 }

 public void onAccuracyChanged(Sensor arg0, int arg1) {
 // TODO Auto-generated method stub

}

public void onSensorChanged(SensorEvent event) {
 // TODO Auto-generated method stub
</code></pre>

<p>}
  }</p>
