How to share: Android gets screen status

Source: Internet
Author: User

<relativelayoutxmlns: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:o rientation= "Vertical" > <!--define buttons to get screen status--<button android:id= "@+id/reenablekeyguard" Androi D:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:text= "the Status of the screen"/> </RelativeLa Yout>

package com.example.yanlei.yl; import android.app.keyguardmanager;import  Android.content.context;import android.os.bundle;importandroid.support.v7.app.appcompatactivity;import  android.view.view;import android.view.view.onclicklistener;import android.widget.button;import  android.widget.toast;   public class mainactivity extendsappcompatactivity  {   //  define the button for the lock screen    private Button btnKeyguard;    //declaring Keyguardmanager objects    private KeyguardManager keyguardManager;       @Override    public void oncreate (bundle savedinstancestate)  {       super.oncreate (savedinstancestate);        setcontentview (R.layout.activity_main);       //  Get Keyguardmanager Service     &Nbsp;  keyguardmanager= (Keyguardmanager) getsystemservice (context.keyguard_service);        //get all objects in the layout        findview ();        //Settings Object Listener        setlistener ();     }    private void findview ()  {        //  get all objects in the layout        btnKeyguard =  (Button)   Findviewbyid (R.id.reenablekeyguard);    }    private void  Setlistener ()  {       //  set listener for object         btnkeyguard.setonclicklistener (New onclicklistener ()  {              @Override             public void onClick (view arg0)  {                 // TODO Auto-generated methodstub                 //Judging 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 lock Screen",  toast.length_short). Show ();                 }            }       });     }}

above, in addition to I will use this: www.ineice.com for all the online security and compatibility testingof the APP.


How to share: Android gets screen status

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.