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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:17:05+00:00 2026-06-19T00:17:05+00:00

I want the users to be able to longpress the volumeUp hardware button for

  • 0

I want the users to be able to longpress the volumeUp hardware button for skipping a song, and do the regular volumeUp action on a short press.

I’m able to differentiate between both (I found this solution, working with flags between onKeyDown, onKeyLongPress and onKeyUp) but I’m wondering if I can still call the standard/super action when the volume up button has been pressed.
I can’t seem to figure out when the volumeUp action is being called (in the onKeyDown- or onKeyUp-event) and where to call it.

Or should I just write my own function to change the volume?

Thanks.

My code:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        event.startTracking();
        if (bLong) {
            bShort = false;
            return true;
        } else {

            bShort = true;
            bLong = false;

            return true;
        }
    }

    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (bShort) {
            bShort = false;
            bLong = false;
            if (mp != null) {
                //HERE IS WHERE I WANT TO CALL THE VOLUME-UP ACTION
            }
            return true;
        }
    }
    return super.onKeyUp(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (bRunning && mp != null) {
            playNextSong();
        }
        bShort = false;
        bLong = false;
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}
  • 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-19T00:17:07+00:00Added an answer on June 19, 2026 at 12:17 am

    Take a look maybe this gonna help you.

    public boolean dispatchKeyEvent(KeyEvent event) {
            int action = event.getAction();
            int keyCode = event.getKeyCode();
    
            switch (keyCode) {
            case KeyEvent.KEYCODE_VOLUME_UP:
                if (action == KeyEvent.ACTION_DOWN && event.isLongPress()) {
                //(skipping a song)
                }
                if (action == KeyEvent.ACTION_UP) {           
                //(vol up)
                }
                return true;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_UP)
    
            return true;
        default:
            return super.dispatchKeyEvent(event);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want users to be able to use the facebook send button to send
Long story short, I want users to be able to call the value of
I want users to be able to upload files via FTP to my site
In my app I want users to be able to associate a file(s) they
Similar Stack Overflow Question I want users to be able to search through my
In my Rails app I want users to be able to input video links
I have an app where we want users to be able to send us
I have a situation where I want users to be able to specify a
I have some pages that I don't want users to be able to access
I am creating a game currently and I want users to be able to

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.