Reputation: 806
I am using Push Notification in my app. I am able to play the Mp3 sound for push . Now i want to set the volume for Mp3. I don't know how to set the volume for push. here is my code for push Sound.
Thread t = new Thread()
{
public void run()
{
MediaPlayer player = null;
player = MediaPlayer.create(GCMIntentService.this,R.raw.traffic);
player.start();
try
{
Thread.sleep(player.getDuration()+100);
}
catch (InterruptedException e)
{
}
}
};
t.start();
Upvotes: 1
Views: 817
Reputation: 806
I solved this . Here is my solution code .
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//am.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_SILENT:
Log.i("MyApp", "Silent mode");
am.setVolumn(0, 0);
break;
case AudioManager.RINGER_MODE_VIBRATE:
Log.i("MyApp", "Vibrate mode");
am.setVolumn(0, 0);
break;
case AudioManager.RINGER_MODE_NORMAL:
Log.i("MyApp", "Normal mode");
am.setVolumn(0, 10);
break;
}
Upvotes: 1