您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
<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: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;
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 {
// 定义锁屏的按钮
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 methodstub
//判断当前屏幕的状态
if(keyguardManager.isKeyguardLocked())
{
Toast.makeText(MainActivity.this, "锁屏",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this,"没有锁屏", Toast.LENGTH_SHORT).show();
}
}
});
}
}
以上,另外对APP进行在线全方位的安全性、兼容性测试,我都会用这个:www.ineice.com。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。