qq_35720183
Android初学者003
2017-01-15 02:37

求教:Android锁屏弹出消息

  • android

正常推送消息已经完成。求教怎么弄锁屏之后推送。
去查了下很多说仿QQ那个,但是我弄了下是整个activity弹出。
我想弄成这样。图片说明
我用网上那个仿QQ弄了之后背景是桌面背景,锁屏都档住了。但是实际我的弹框高才50dp。
class LocalBroadcastReceiver extends BroadcastReceiver{

    @SuppressLint("NewApi")
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("LOG_TAG", intent.getAction());
        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        if (km.isKeyguardLocked()) {
            Intent alarmIntent = new Intent(context, AlarmActivity.class);
            alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(alarmIntent);
        }
    }
}

弹框activity
@Override
protected void onCreate(Bundle savedInstanceState) {
    final 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); //打开屏幕
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
}

@Override
protected void onNewIntent(Intent intent) {
    // TODO Auto-generated method stub
    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();  
    }  
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答