0

I'm trying to develop an android app that will replace the stock lock screen and acquire the basic functionality of a typical lock screen. I'm planning to support the app from API level 15 and higher. But I'm facing some problem regarding lock screen behaviour. I'm not yet able to disable the home and recent button of soft navigation bar. I've found lot of examples in stack, github and other sources but those are not so useful.

I've tried in following way:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

Added following flags in LockActivity

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                    WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_FULLSCREEN
                    | WindowManager.LayoutParams.FLAG_DIM_BEHIND);

But didn't get any effective solutions. I've found ZUI Locker a very nice app doing what I actually want. How they are accessing the permissions to work like a default lock screen ?

Any suggestions ? Thanks in advance!

Pitty
  • 1,907
  • 5
  • 16
  • 34
T.S
  • 1
  • You need to make a guide to let user to disable system lockscreen in Settings(by send a intent), after user block the system screen, your lock screen will work perfectly. – SHICONG CAO Mar 21 '16 at 07:16
  • @SHICONGCAO didn't work in this way. Do you think I need to acquire some permissions (like device admin) to have the functionality ? – T.S Mar 21 '16 at 11:18

1 Answers1

0

I've developed a lockscreen app too and I'd like to help you too.

You can check out the answer here for understanding the concept behind Views and TYPE_SYSTEM_ERROR.

But I tweaked the code a bit and here's my version:

WindowManager mWindowManager;
RelativeLayout mLscreenlayout;

WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
             WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
             WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|
             WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH|
             WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN|
             View.SYSTEM_UI_FLAG_LAYOUT_STABLE| 
             View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION|
             View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|
             View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
             View.SYSTEM_UI_FLAG_FULLSCREEN,
            PixelFormat.TRANSLUCENT);
     mWindowManager = ((WindowManager)getApplicationContext().getSystemService(WINDOW_SERVICE));
     mLscreenlayout = new RelativeLayout(getApplicationContext());
     getWindow().setAttributes(localLayoutParams);


     View.inflate(this, R.layout.activity_lockscreen, this.mLscreenlayout);
     this.mWindowManager.addView(mLscreenlayout, localLayoutParams); 

public void onDestroy()
    {
        mWindowManager.removeView(this.mLscreenlayout);
        mLscreenlayout.removeAllViews();

        super.onDestroy();
        //myThread.interrupt();
        Log.i("Daze","Lockscreen Activity Destroyed");
    }

Also, there's library on GitHub here to lock the home button. Hope this helps :)

Community
  • 1
  • 1
Bikraman
  • 31
  • 6