-1

I'm working on an application .. but Audiomanager is not working i can't see any error my application got crash on phone I'm using AudioManager in BroadCastReciver Class when sms recive and text of sms is same of the particular text i've set the volume should be change silent to Normal mode.

if(message.equals(pwd)) {

    AudioManager au;
    au = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    au.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

    // Show Alert
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(context, "Volumn Changed By Phone Finder App", duration);
    toast.show();
}
else {

    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(context,  "Doesn't match", duration);
    toast.show();
}
Luciano Rodríguez
  • 2,239
  • 3
  • 19
  • 32
  • Please, post your logcat message. What does it say? – Yurets May 01 '15 at 10:00
  • If you just want to set volume to full, try this: **int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); au.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_PLAY_SOUND);** – Rahul Sharma May 01 '15 at 10:34
  • @ au = (AudioManager)getSystemService(Context.AUDIO_SERVICE); GetSystemService shows an error like method is undefined for this type then i right clicked and click on create method it created a method with same name and that method is returning Null.. I think this is the problem! – Shaikh Noman Nasir May 01 '15 at 15:08
  • Please post your class and logcat error message. – Kirankumar Zinzuvadia May 02 '15 at 05:35

1 Answers1

0

Your code is working well without crash. Please paste log report of crash.

And its better to check context, message and pwd for NullPointer Exception.

Kirankumar Zinzuvadia
  • 1,249
  • 10
  • 17
  • @ au = (AudioManager)getSystemService(Context.AUDIO_SERVICE); GetSystemService shows an error like method is undefined for this type then i right clicked and click on create method it created a method with same name and that method is returning Null.. I think this is the problem! – Shaikh Noman Nasir May 01 '15 at 15:09