importandroid.app.KeyguardManager;importandroid.app.WallpaperManager;importandroid.content.Context;importandroid.content.Intent;importandroid.graphics.drawable.Drawable;importandroid.os.Bundle;importandroid.support.v7.app.AppCompatActivity;importandroid.util.Log;importandroid.view.View;importandroid.view.Window;importandroid.view.WindowManager;importcom.demo.lockscreenmsgdemo.R;/*** 锁屏消息内容的activity*/
public class MessageActivity extendsAppCompatActivity {privateContext mContext;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
Log.i("tag", "onCreate:启动了消息内容的activity ");//四个标志位顾名思义,分别是锁屏状态下显示,解锁,保持屏幕长亮,打开屏幕。这样当Activity启动的时候,它会解锁并亮屏显示。
Window win =getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED//锁屏状态下显示
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD //解锁
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON //保持屏幕长亮
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //打开屏幕//使用手机的背景
Drawable wallPaper = WallpaperManager.getInstance(this).getDrawable();
win.setBackgroundDrawable(wallPaper);
setContentView(R.layout.activity_message);
mContext= this;
initView();
}
@Overrideprotected voidonNewIntent(Intent intent) {super.onNewIntent(intent);//获取电源管理器对象//PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);//if (!pm.isScreenOn()) {//PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP |//PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");//wl.acquire();//点亮屏幕//wl.release();//任务结束后释放//}
}private voidinitView() {
findViewById(R.id.message_layout).setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View view) {//先解锁系统自带锁屏服务,放在锁屏界面里面
KeyguardManager keyguardManager =(KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
keyguardManager.newKeyguardLock("").disableKeyguard(); //解锁//点击进入消息对应的页面
mContext.startActivity(new Intent(mContext, DetailsActivity.class));
finish();
}
});
findViewById(R.id.close_iv).setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View view) {
finish();
}
});
}
}