Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:25:30+00:00 2026-06-11T05:25:30+00:00

I’m new developing on Android. I’m have a view with a ToggleButton on it

  • 0

I’m new developing on Android. I’m have a view with a ToggleButton on it that when pushed will turn off all sound until the ToggleButton is pushed again.

Currently, I have this code. I can see the logging events happening, but the sound is not turning off. Can anyone provide some insight?

 public void onToggleClicked(View view) {
    Log.i("onToggleClicked", "ToggleClick Event Started");
    // Is the toggle on?
    boolean on = ((ToggleButton) view).isChecked();

    if (on) {
        Log.i("onToggleIsChecked", "ToggleClick Is On");
        //turn off sound, disable notifications
        amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
        Log.i("STREAM_SYSTEM", "Set to true");
        //notifications
        amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
        Log.i("STREAM_NOTIFICATION", "Set to true");
        //alarm
        amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
        Log.i("STREAM_ALARM", "Set to true");
        //ringer
        amanager.setStreamMute(AudioManager.STREAM_RING, true);
        Log.i("STREAM_RING", "Set to true");
        //media
        amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
        Log.i("STREAM_MUSIC", "Set to true");

    } else {
        Log.i("onToggleIsChecked", "ToggleClick Is Off");
        // turn on sound, enable notifications
        amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
        Log.i("STREAM_SYSTEM", "Set to False");
        //notifications
        amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
        Log.i("STREAM_NOTIFICATION", "Set to False");
        //alarm
        amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
        Log.i("STREAM_ALARM", "Set to False");
        //ringer
        amanager.setStreamMute(AudioManager.STREAM_RING, false);
        Log.i("STREAM_RING", "Set to False");
        //media
        amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
        Log.i("STREAM_MUSIC", "Set to False");
    }
    Log.i("onToggleClicked", "ToggleClick Event Ended");
}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:25:31+00:00Added an answer on June 11, 2026 at 5:25 am

    I was able to make it work by changing the event to a listener

        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        //create the toggle button ref and instantiate
        ToggleButton tb = (ToggleButton)this.findViewById(R.id.tglSetStatus);
        tb.setTextOff(getString(R.string.available_status));
        tb.setTextOn(getString(R.string.driving_status));
        //default to being available
        tb.setChecked(false);
        // attach an OnClickListener
        tb.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                // your click actions go here
                Log.i("onToggleClicked", "ToggleClick Event Started");
                //an AudioManager object, to change the volume settings  
                AudioManager amanager; 
                amanager = (AudioManager)getSystemService(AUDIO_SERVICE);
    
                // Is the toggle on?
                boolean on = ((ToggleButton)v).isChecked();
    
                if (on) {
                    Log.i("onToggleIsChecked", "ToggleClick Is On");
                    //turn ringer silent
                    amanager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                    Log.i("RINGER_MODE_SILENT", "Set to true");
    
                    //turn off sound, disable notifications
                    amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
                    Log.i("STREAM_SYSTEM", "Set to true");
                    //notifications
                    amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
                    Log.i("STREAM_NOTIFICATION", "Set to true");
                    //alarm
                    amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
                    Log.i("STREAM_ALARM", "Set to true");
                    //ringer
                    amanager.setStreamMute(AudioManager.STREAM_RING, true);
                    Log.i("STREAM_RING", "Set to true");
                    //media
                    amanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
                    Log.i("STREAM_MUSIC", "Set to true");
    
                } else {
                    Log.i("onToggleIsChecked", "ToggleClick Is Off");
    
                    //turn ringer silent
                    amanager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                    Log.i(".RINGER_MODE_NORMAL", "Set to true");
    
                    // turn on sound, enable notifications
                    amanager.setStreamMute(AudioManager.STREAM_SYSTEM, false);
                    Log.i("STREAM_SYSTEM", "Set to False");
                    //notifications
                    amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
                    Log.i("STREAM_NOTIFICATION", "Set to False");
                    //alarm
                    amanager.setStreamMute(AudioManager.STREAM_ALARM, false);
                    Log.i("STREAM_ALARM", "Set to False");
                    //ringer
                    amanager.setStreamMute(AudioManager.STREAM_RING, false);
                    Log.i("STREAM_RING", "Set to False");
                    //media
                    amanager.setStreamMute(AudioManager.STREAM_MUSIC, false);
                    Log.i("STREAM_MUSIC", "Set to False");
                }
                Log.i("onToggleClicked", "ToggleClick Event Ended");
            }
        });
    

    I found input by looking at these questions: How to turn off all sounds and vibration via Android API
    and this one: attach onClickListener to ToggleButton

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.