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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:12:56+00:00 2026-06-14T01:12:56+00:00

here i am trying to determine whether the screen is on or not but

  • 0

here i am trying to determine whether the screen is on or not but it doesn’t seems to be working when press power lock/unlock button. Application works with no error but the code in if-else doesnt seems to have effect.
Edited
now the code work(thanks Olgun) but the mediaplayer playback doesnt stops and every time on/off screen new mediaplayer objct is created(multiple playbacks ).

SCBroadcaster.java

    public class SCBroadcaster extends BroadcastReceiver {
    PowerManager pm;
    MediaPlayer mp;
    public static boolean wasScreenOn = true;

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        // TODO Auto-generated method stub
        mp = MediaPlayer.create(arg0, R.raw.gale);
        if (arg1.getAction().equals(Intent.ACTION_SCREEN_ON)) {
                    mp.stop();
            mp.release();
            Toast.makeText(arg0, "oNONONO", Toast.LENGTH_LONG).show();

        } else if (arg1.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            mp.start();
        }

    }

}

MainActivity.java

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    BroadcastReceiver bre = new SCBroadcaster();
    registerReceiver(bre, filter);
}

protected void onPause() {
    super.onPause();
    if (SCBroadcaster.wasScreenOn) {
        System.out.println("SCREEN TURNED OFF");
    } else {

    }
}

protected void onResume() {
    super.onResume();
    if (!SCBroadcaster.wasScreenOn) {

    } else {

    }
}

}

  • 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-14T01:12:57+00:00Added an answer on June 14, 2026 at 1:12 am

    Intent.ACTION_SCREEN_OFF and ACTION_SCREEN_ON check out for above broadcasts registration. here you can find a good example.

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

Sidebar

Related Questions

I'm trying to determine whether or not the user has voted on a certain
I am trying to determine whether a string contains a positive int or not.
Beginner here trying to get a pipeline working in bash. If somebody can see
I know of the ||= operator, but don't think it'll help me here...trying to
I am trying to determine whether a string input by a user is valid
Is it possible to determine whether or not a given registry key is redirected?
I'm not sure if this is the right place to ask, but here goes...
Note: I am not trying to determing whether or not a generic parameter is
We are trying to determine whether we are using Service Broker appropriately and getting
I'm not sure if VLOOKUP() is the function I am looking for, but here

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.