首页 > 代码库 > Android锁屏状态下弹出activity,如新版qq的锁屏消息提示

Android锁屏状态下弹出activity,如新版qq的锁屏消息提示

在接收消息广播的onReceive里,跳转到你要显示的界面。如:

  1. Intent intent = new Intent(arg0,MainActivity.class);
  2. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        
  3. arg0.startActivity(intent);

在该activity的onCreate()方法里:

  1. super.onCreate(savedInstanceState);
  2. getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
  3. setContentView(R.layout.activity_main);


设置activity的theme属性:

  1. android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
添加点击事件,进入app,突破锁屏:
  1. KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
  2. KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("");
  3. keyguardLock.disableKeyguard();
在menifest中加入该权限:
  1. <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>

Android锁屏状态下弹出activity,如新版qq的锁屏消息提示