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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:12+00:00 2026-05-22T14:53:12+00:00

I need catch long press of volume button when phone is sleeping(screen off) and

  • 0

I need catch long press of volume button when phone is sleeping(screen off) and I know this code:

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 
    {
        // to your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

is not helpful(it works only in active intent

  • 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-05-22T14:53:13+00:00Added an answer on May 22, 2026 at 2:53 pm

    I’m curious about this too.
    While this isn’t necessarily an answer, I have done some research on Services (to catch the volume press I’m guessing) and BroadcastReceivers (onReceive() would receive an intent for ACTION_SCREEN_OFF and probably set a flag for the screen being off). My thinking is starting the service when the screen turns off and kill it when the screen turns on, but I don’t know how to join onKeyLongPress and the service.

    The sequence I see happening is this: Screen turns off -> BroadcastReceiver receives this command and starts the service to watch for volume press -> receive volume press and do your logic -> kill the service if the screen turns on.

    I found a site that apparently handles screen off/on and has an example for an activity and a service but I can’t get something together yet:
    http://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/

    One thing I’m worried about when using a service is battery life and processing time but that will be testing down the road. I will hopefully be able to mitigate that with killing the service when the screen turns on. I’ll try to keep this entry updated as I make progress.

    Good luck!

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

Sidebar

Related Questions

I need to catch segmentation fault in third party library cleanup operations. This happens
Code: catch (IOException e) { LOGGER.error(IOException exception happened); //now need throw again the same
First, it is long post so if you need clarification please let me know.
my task is to do a long running JS code. This routine generate a
I need to know how to do this procedure. calculation1: 1/4 = 0,25 calculation2:
I need to know if there are any issues with the below code as
This is my below code which converts string to long datatype. /** * Parses
The code for this is too long to post so Ill just describe it.
I need to catch or filter a number from string example: var Mystring =
I need to catch two exceptions because they require the same handling logic. 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.