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 7745125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:56:06+00:00 2026-06-01T09:56:06+00:00

I have an application with the desired functionality. Howerver, at certain times toasts are

  • 0

I have an application with the desired functionality.

Howerver, at certain times toasts are displayed and I want a double beep to play at the same time that the toasts are displayed to alert the user to the messages being displayed.

I’m not sure what the best approach is for playing sounds in android or if there is some default sounds that I could access to use for the alerts.

UPDATE

I have the following code in my main activity file:

  public void playAlertTone(final Context context){
            Thread t = new Thread(){
                    public void run(){
                        MediaPlayer player = null;
                        int countBeep = 0;
                        while(countBeep<2){
                        player = MediaPlayer.create(context,R.raw.beep);
                        player.start();
                        countBeep+=1;
                        try {

                                        
                            Thread.sleep(player.getDuration()+100);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        }
                    }
                };
                t.start();   

            }

I have a sound file named beep in res/raw

How can I call this method in an if statement where a toast is displayed so the 2 occur at the same time?

UPDATE 2:

Here is the code where I’m trying to call the alerting method:

  if (elapsedTime > hourAlert)
        {
            LayoutInflater inflater = getLayoutInflater();
            View layout = inflater.inflate(R.layout.toast_layout,
                                           (ViewGroup) findViewById(R.id.toast_layout_root));
            TextView text = (TextView) layout.findViewById(R.id.text);
            text.setText("HOUR PASSED");

            Toast toast = new Toast(getApplicationContext());
            toast.setGravity(Gravity.BOTTOM, 0, 160);
            toast.setDuration(Toast.LENGTH_LONG);
            toast.setView(layout);
            toast.show();
            playAlertTone(getApplicationContext()); // Edited here now call
  • 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-01T09:56:07+00:00Added an answer on June 1, 2026 at 9:56 am

    You can put your audio file in res/raw folder of your Project

    and play audio in a thread

    public  void playAlertTone(final Context context){
    
          
        Thread t = new Thread(){
                public void run(){
                    MediaPlayer player = null;
                    int countBeep = 0;
                    while(countBeep<2){
                    player = MediaPlayer.create(context,R.raw.beep);
                    player.start();
                    countBeep+=1;
                    try {
                                             
                                    // 100 milisecond is duration gap between two beep
                        Thread.sleep(player.getDuration()+100);
                                           player.release();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                               
    
                    }
                }
            };
    
            t.start();   
            
        }
    
    //call it like this from your activity' any method
    
    
    
        if(myCondition){
        
        Toast.makeText(getApplicationContext(), text, duration).show();
        
        playAlertTone(getApplicationContext());
        
        
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows desktop application that I want to add some functionality to.
I have Application settings stored under HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany branch. Settings must be same for different
I have an application developed in netbeans and I want to set the focus
I have an Mac Application, and when I launch it the first time, a
I have application which needs to use a dll (also written by me) which
I have application that makes different queries with different results so the caching in
I have Application written with GWT 1.7. I have one page where I upload
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have Application X (not mine!) with Subform x1, x2, x3. How can I

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.