<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