deathnote
deathnote

Reputation: 95

How to change the ringing state of android phone?

I'm trying to silent my phone when any call is ended and for that i'm using audiomanager object. When i write setRingerMode at position 1 it works but at position 2 its not working. Its inside BroadCast Recevier. Here is my code:

public void onReceive(Context context, Intent intent)
    {   


        AudioManager am= (AudioManager)context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);

        //POSITION 1    am.setRingerMode(AudioManager.RINGER_MODE_SILENT);


        Bundle myBundle = intent.getExtras();
        if (myBundle != null)
        {
          System.out.println("--------Not null-----");
            try 
            {
                if (intent.getAction().equals("android.intent.action.PHONE_STATE")) 
                { 
                    String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);


                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING))
                    { 

                           //code...
                    }
                    else if (state1.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
                    {   
                           //POSITION 2
                                am.setRingerMode(AudioManager.RINGER_MODE_SILENT);

                    }
              }

         }
            catch (Exception ex) 
            { // Many things can go wrong with reflection calls
                ex.printStackTrace();
            }
        }
}

Upvotes: 0

Views: 87

Answers (1)

Gautam
Gautam

Reputation: 3362

As per android documentation -

Device call state: Off-hook. At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.

if you want to set after the call is ended use EXTRA_STATE_IDLEand in your code you have used state1variable in if statement and you have declared and used statevariable.

Upvotes: 1

Related Questions