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

  • Home
  • SEARCH
  • 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 6095263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:32+00:00 2026-05-23T12:47:32+00:00

Is it possible to override the function of a hardware button programmically on a

  • 0

Is it possible to override the function of a hardware button programmically on a droid? Specifically, I’d like to be able to override the camera button on my phone programmically. Is this possible?

  • 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-23T12:47:33+00:00Added an answer on May 23, 2026 at 12:47 pm

    How to Handle Camera Button Events

    As soon as camera button is pressed a broadcast message is sent to all the applications listening to it. You need to make use of Broadcast receivers and abortBroadcast() function.

    1) Create a class that extends BroadcastReceiver and implement onReceive method.

    The code inside onReceive method will run whenever a broadcast message is received. In this case I have written a program to start an activity called myApp.

    Whenever hardware camera button is clicked the default camera application is launched by the system. This may create a conflict and block your activity. E.g If you are creating your own camera application it may fail to launch because default camera application will be using all the resources. Moreover there might be other applications which are listening to the same broadcast. To prevent this call the function “abortBroadcast()”, this will tell other programs that you are responding to this broadcast.

    public class HDC extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
    // Prevent other apps from launching
         abortBroadcast();
    // Your Program
         Intent startActivity = new Intent();
            startActivity.setClass(context, myApp.class);
            startActivity.setAction(myApp.class.getName());
            startActivity.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            context.startActivity(startActivity);
            }
        }
    }
    
    2) Add below lines to your android manifest file.
    
    <receiver android:name=".HDC" >
        <intent-filter android:priority="10000">         
            <action android:name="android.intent.action.CAMERA_BUTTON" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>            
    </receiver>
    

    The above lines are added to your manifest file to tell the system that your program is ready to receive broadcast messages.

    This line is added to receive an intimation when hardware button is clicked.

    <action android:name="android.intent.action.CAMERA_BUTTON" />
    

    HDC is the class created in step 1(do not forget the “.”)

    <receiver android:name=".HDC" >
    

    The “abortBroadcast()” function is called to prevent other applications from responding to the broadcast. What if your application is the last one to receive the message? To prevent this some priority has to be set to make sure that your app receives it prior to any other program. To set priority add this line. Current priority is 10000 which is very high, you can change it according to your requirements.

    <intent-filter android:priority="10000">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Software Utilize : C#, VS-2005 Is This Possible to override Shift+Tab Function/Method or detect
Is it possible to override a generisized function as illustrated in the code snippet
Is it possible to override a function based on the number of parameters that
Possible Duplicate: Override default php function Is there a way to detect that a
I have a parent class containing a function funcB() which I like to override
Is it possible to override the call function on a generic level, so that
I was wondering if it's possible to override just one function in a class
Is it possible in C++ to have a class override a virtual function, but
Possible Duplicates: Overriding vs Virtual How am i overriding this C++ inherited member function
Is it possible to override default value of WebClientProtocol.Timeout property via web.config? <httpRuntime executionTimeout=500

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.