zoukankan      html  css  js  c++  java
  • android 获得屏幕状态

    <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" >
        <!-- 定义获得屏幕状态的按钮 -->
        <Button
            android:id="@+id/reenableKeyguard"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="屏幕的状态" />
    
    
    </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 {
        // 定义锁屏的按钮
        private Button btnKeyguard;
        //声明KeyguardManager对象
        private KeyguardManager keyguardManager;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // 获得KeyguardManager服务
            keyguardManager=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
            //得到布局中的所有对象
            findView();
            //设置对象的监听器
            setListener();
        }
    
        private void findView() {
            // 得到布局中的所有对象
            btnKeyguard = (Button) findViewById(R.id.reenableKeyguard);
        }
    
        private void setListener() {
            // 设置对象的监听器
            btnKeyguard.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    //判断当前屏幕的状态
                    if(keyguardManager.isKeyguardLocked())
                    {
                        Toast.makeText(MainActivity.this, "锁屏", Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        Toast.makeText(MainActivity.this, "没有锁屏", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    }
  • 相关阅读:
    网络安全分析
    java实现 洛谷 P1464 Function
    java实现 洛谷 P1464 Function
    java实现 洛谷 P1014 Cantor表
    java实现 洛谷 P1014 Cantor表
    java实现 洛谷 P1014 Cantor表
    java实现 洛谷 P1014 Cantor表
    java实现 洛谷 P1014 Cantor表
    java实现 洛谷 P1540 机器
    java实现 洛谷 P1540 机器
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5009721.html
Copyright © 2011-2022 走看看