Android Question kiosk-mode variant

peacemaker

Expert
Licensed User
Longtime User
Hi all,

How to make such locking variant ?
With possibility to remove this locking-window and start regular app activity.

B4X:
...
mRl = new RelativeLayout(this);
mRl.setBackgroundColor(0x80000000);
mRl.setOnKeyListener(new OnKeyListener(){

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
Log.d("LockScreen", "keyCode = "+keyCode);
return true;
}

});

...
mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.FILL_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,

// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_FULLSCREEN,
PixelFormat.TRANSLUCENT);
...
mWindowManager = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
...
mWindowManager.addView(mRl, mParams);
...
Unlock password is "7777"
 

Attachments

  • TestSystemAlertWindow.apk
    27.8 KB · Views: 443
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim jo As JavaObject
   jo.InitializeContext
   jo.RunMethod("lockScreen", Null)
End Sub

#if Java
import android.content.Context;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnKeyListener;
import android.widget.RelativeLayout;
public void lockScreen() {
 RelativeLayout mRl = new RelativeLayout(this);
    mRl.setBackgroundColor(0x80000000);
    mRl.setOnKeyListener(new OnKeyListener(){

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
    Log.d("LockScreen", "keyCode = "+keyCode);
    return true;
    }

    });

    WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.FILL_PARENT,
    WindowManager.LayoutParams.FILL_PARENT,
    WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,

    // Draws over status bar
    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    | WindowManager.LayoutParams.FLAG_FULLSCREEN,
    PixelFormat.TRANSLUCENT);
    WindowManager
    mWindowManager = (WindowManager) this
    .getSystemService(Context.WINDOW_SERVICE);
    mWindowManager.addView(mRl, mParams);
   }
#End If

You need to add the permission:
B4X:
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)

I've set the targetSdkVersion to 8.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Thanks, Erel !
So, it's turned out not full Java-code of the APK-sample, without Textview for password and checking the password.

This system window locks whole the screen and HOME button well.
But it needs to add some interface to unlock the screen: seems, Textview for a password is needed, and the button "Unlock", that runs the password checking.

How to join such Java to B4A views and events ? Or here all must be inside Java code only?
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hmmm, but how to remove this System alert window ? Unlock the device.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…