set Media Volume - Android Phone

Android examples for Phone:Volume

Description

set Media Volume

Demo Code


//package com.java2s;

import android.content.Context;

import android.provider.Settings;

public class Main {

    public static boolean setMediaVolume(Context context, int mediaVloume) {
        if (mediaVloume < 0) {
            mediaVloume = 0;//from ww w  .ja  va2 s .  c o m
        } else if (mediaVloume > 15) {
            mediaVloume = mediaVloume % 15;
            if (mediaVloume == 0) {
                mediaVloume = 15;
            }
        }
        return Settings.System.putInt(context.getContentResolver(),
                "volume_music", mediaVloume);
        //            Settings.System.VOLUME_MUSIC, mediaVloume);
    }
}

Related Tutorials