Android gets the screen status, android gets the screen

Source: Internet
Author: User

Android gets the screen status, android gets the screen

<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <! -- Define the Button for obtaining the screen status --> <Button android: id = "@ + id/reenableKeyguard" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: text = "screen status"/> </RelativeLayout>
Package com. example. yanlei. yl; import android. app. keyguardManager; import android. content. context; import android. OS. bundle; import android. support. v7.app. appCompatActivity; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. toast; public class MainActivity extends AppCompatActivity {// define the lock screen Button private Button btnKeyguard; // declare the KeyguardManager object private KeyguardManager keyguardManager; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // obtain the KeyguardManager service keyguardManager = (KeyguardManager) getSystemService (Context. KEYGUARD_SERVICE); // obtain all objects in the layout. findView (); // set the object listener setListener ();} private void findView () {// get all objects in the layout btnKeyguard = (Button) findViewById (R. id. reenableKeyguard);} private void setListener () {// sets the object listener btnKeyguard. setOnClickListener (new OnClickListener () {@ Override public void onClick (View arg0) {// TODO Auto-generated method stub // determine the status of the current screen if (keyguardManager. isKeyguardLocked () {Toast. makeText (MainActivity. this, "lock screen", Toast. LENGTH_SHORT ). show ();} else {Toast. makeText (MainActivity. this, "no screen lock", Toast. LENGTH_SHORT ). show ();}}});}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.