Guys, how to turn off the sound in the application in the fragment? I have a fragment in which I want to make settings, but this line of code swears:

AudioManager amanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE); 

In Activity does not swear, in a fragment swears. How do I initialize an AudioManager in a fragment?

Don't swear at me if this is an easy problem for someone, I'm new

    1 answer 1

    I understand swore on getSystemService . Try using getActivity() . Like this:

      AudioManager amanager=(AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); 
    • Thanks, helped) - shcherbuk