Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.SharedPreferences;

import android.media.AudioManager;
import android.preference.PreferenceManager;

public class Main {
    private static final String VivaVolume = "VivaVolume";

    public static void setVivaVolume(Context context, int volume) {
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
        getPreferences(context).edit().putInt(VivaVolume, volume).apply();
    }

    /**
     * Default Preference Helper
     * @param context - the calling application context.
     * @return Shared Preferences
     */
    private static SharedPreferences getPreferences(Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }
}