3

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.

tekkavi
  • 904
  • 10
  • 19

3 Answers3

2

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.

Pishang Ujeniya
  • 176
  • 5
  • 13
1

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.

Jatin Malwal
  • 5,133
  • 2
  • 23
  • 26
  • I am aware of how to show it via Activity, thats why i mentioned that i will be using WindowManager.addView() Thanks for the effort though. – tekkavi Sep 11 '13 at 05:25
0
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;
    }

    }
Charuක
  • 12,953
  • 5
  • 50
  • 88
Sumit Kandoi
  • 427
  • 4
  • 12