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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:54:27+00:00 2026-06-16T03:54:27+00:00

I am developing torch. I have developed widget with a single button. If you

  • 0

I am developing torch. I have developed widget with a single button. If you click on that button it turns on torch and if you click again it turns off torch. BUT when torch is ON and user pressed Power button to turn off screen it also turns off the torch. So I want to check if device has gone to sleep mode while torch was on, can someone help me ?

here is my code to turn torch on and off in widget

public void onReceive(Context context, Intent intent) {
    Log.d("torchWidget", "onReceive");
    final String action = intent.getAction();
    if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
        final int appWidgetId = intent.getExtras().getInt(
                AppWidgetManager.EXTRA_APPWIDGET_ID,
                AppWidgetManager.INVALID_APPWIDGET_ID);
        if(appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
            this.onDeleted(context, new int[] { appWidgetId });
        }
    } else{

        if(intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
            String msg = "null";
            try{
                msg = intent.getStringExtra("msg");
                msg = "Flash Turned On";
            } catch(NullPointerException e) {
                Log.e("Error", "msg = null");
            }
            if(Constants.isFlashOnWidget){
                Constants.isFlashOnWidget = false;
                Toast.makeText(context, "Flash turned OFF", Toast.LENGTH_SHORT).show();

                 Intent serviceIntent = new Intent(context.getApplicationContext(),
                         BackgroundService.class);

                        context.stopService(serviceIntent);

            } else {   
                Constants.isFlashOnWidget = true;
                 Intent serviceIntent = new Intent(context.getApplicationContext(),
                         BackgroundService.class);

                        context.startService(serviceIntent);

            }

        }
        super.onReceive(context, 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-06-16T03:54:28+00:00Added an answer on June 16, 2026 at 3:54 am

    Check isScreenOn() method from PowerManager system service

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

Sidebar

Related Questions

I am developing a widget for turning on/off camera led of phone. I have
I have a responsive site that I'm developing where I'm using a image slider
I am developing an app which supposed to work on devices that have OS
I have a Pure AS3 mobile project that I'm developing in Flex 4.5, and
I'm developing custom Media Controller and i have taken four button(play/pause,next,pre and bandwidth)inside a
I have been developing a game and I'm confuse that How can I use
I have iPod touch 4th. And I'm developing iPhone app with it. I use
I'm developing a game where the user creates sprites with every touch. I then
I'm developing my own OS, but for this I need to touch on linking,
Developing for Android 2.3, I have a question regarding layouts. I use a vertival

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.