Flags to show a view on top of lock screen

别等时光非礼了梦想. 提交于 2019-12-09 19:04:55

问题


I am trying to add a view(ImageButton for example) to Window using WindowManager.addView(button),

What are the layout params so that the button can be seen on "lock screen".

Thanks in advance.


回答1:


You can try adding type as WindowManager.LayoutParams.TYPE_SYSTEM_ERROR in the WindowManager.LayoutParams constructor which is illustrated below :

WindowManager.LayoutParams params=new WindowManager.LayoutParams();
params.type=WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;

The aforementioned lines will make the view to appear on lock screen where you can capture touch events, click events and many others; However, you can use the below-mentioned flag for the non-touchable view.

WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY

Note: As per Android Developers The above-mentioned both flags are deprecated in API Level 26 and so you can use the flag TYPE_APPLICATION_OVERLAY as a substitute.




回答2:


You have to make an activity with transparent background with view on the top which you want to show on the lockscreen. Now call that activity when your phone wakes up. Note : You have to make an service which will start your activity. You have to register a broadcast receiver to that service.




回答3:


public class CrackService extends Service 

    {

         CrackView renderView;
         LayoutParams params;
         WindowManager wm;

       @Override

      public void onCreate()

     {


          params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
                        WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                        PixelFormat.TRANSLUCENT);
                        params.gravity = Gravity.RIGHT | Gravity.TOP;

                        wm = (WindowManager) getSystemService(WINDOW_SERVICE);
                        wm.addView(renderView, params);

    }

    @Override

    public IBinder onBind(Intent intent) 
    {

            // TODO Auto-generated method stub
            return null;
    }

    }


来源:https://stackoverflow.com/questions/18717397/flags-to-show-a-view-on-top-of-lock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!