I wrote this app where users can toggle silent mode by clicking on an image button: package p.a;
import android.media.AudioManager;
import android.support.v7
You can do it as Vamshi Krishna says, it's totally a good answer for this problem, but if you don't want to instantiate it for some reason you could change "Mode class" to a "Mode static class" as follows:
package p.a;
import android.media.AudioManager;
/**
* Created by root on 9/19/17.
*/
public static class mode {
public static boolean phonesilent(AudioManager audioManager){
return audioManager.getRingerMode()==AudioManager.RINGER_MODE_SILENT;
}
public static void toggle(AudioManager audioManager){
int mode = phonesilent(audioManager)?
AudioManager.RINGER_MODE_NORMAL:
AudioManager.RINGER_MODE_SILENT;
}
}
Hope it helps!
Firstly create a Mode Object like this :
Mode mode = new Mode();