Selective silent mode
<p>I had  developed an app which  will selectively rings for certain numbers even if the phone is in silent mode.I had written the code for making it louder in a broadcast receiver.</p>

<p>The broadcast receiver is</p>

<pre><code>     AudioManager am = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

     switch (am.getRingerMode()) {
         case AudioManager.RINGER_MODE_SILENT:
             Log.i("MyApp","Silent mode");
             profileStatus = 1;
             break;
         case AudioManager.RINGER_MODE_VIBRATE:
             Log.i("MyApp","Vibrate mode");
             break;
         case AudioManager.RINGER_MODE_NORMAL:
             Log.i("MyApp","Normal mode");
             profileStatus= 2;
             break;
     }
    System.out.println("The Profile Status"+profileStatus);
    System.out.println("The Old Profile Status"+oldProfileStatus);
    System.out.println("The Count = "+count  );

  if(profileStatus==1)
  {
        System.out.println("ProfileStatus"+profileStatus);

     OpenHelper db = new OpenHelper(context);
     //Getting Data From The DataBase

     CONTACT_DATA = db.Contact_Records();

     if (CONTACT_DATA.size() &gt; 0)
     {
       //Log.e("ARRAY", "not null"); 

       for(int i =0;i&lt;CONTACT_DATA.size();i++)
       {
           HashMap&lt;String, String&gt; map = CONTACT_DATA.get(i); 
           phone_number     =  map.get("phone_number"); 
       }
     }


         Bundle bundle = intent.getExtras();
         final AudioManager mobilemode = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
         if(null == bundle)
                 return;

         Log.i("IncomingCallReceiver",bundle.toString());

         String state = bundle.getString(TelephonyManager.EXTRA_STATE);

         Log.i("IncomingCallReceiver","State: "+ state);
         if(state.equals("IDLE"))
         {

             System.out.println("THE STATE IS IDLE");
             mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);

         }



         if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
         {
                 String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);        
                 Log.i("IncomingCallReceiver","Incomng Number:from receiver------------------ " + phonenumber);
                 String info = "Detect Calls sample application\nIncoming number: " + phonenumber;



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

                           for(int i =0;i&lt;CONTACT_DATA.size();i++)
                           {
                               HashMap&lt;String, String&gt; map = CONTACT_DATA.get(i); 
                               phone_number     =  map.get("phone_number"); 
                                 if (PhoneNumber.equals(phone_number)) {
                                }
                            if((PhoneNumber.equals(phone_number)))
                            {
                                makeitNormal();
                                maudio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                                oldProfileStatus = profileStatus;
                                System.out.println("The Profile Status==="+oldProfileStatus);
                                count=1;
                            }
                           }

                 }
                 if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_OFFHOOK))
                 {
                     makeItSilent();
                     mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                 }

                 if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE))
                 {
                     makeItSilent();
                     mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);

                 }
</code></pre>

<p>//                </p>

<pre><code> }
         }
  else
  {
      System.out.println("The System  Is In Normal Mode ");
      count=0;
  }
 }
 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>The problem i am facing is
1)It is not ringing on the first time after the installation.After that it works perfectly
2)It is not working in HTC phone but it is working in samsung</p>
