user3047494 user3047494 - 2 months ago 21
Java Question

Creating an Android Lock Screen App.

How to create a lock-screen app that acts as a lock for android mobile. I did find one, But it was poorly constructed code wise and if I pressed the physical home key, it unlocked, making the application pointless.

I did come across a forum stating some method of blocking home button functionality was removed in Android 4.x

Yet, I have an awesome idea for a lock-screen but no ground to get started. If anyone has any knowledge on the subject, I'd love to hear it.

Thanks all :-)

Answer

Yes, it is possible. This is a simple lock screen source code from GitHub

Creating an app that works like a lock is no big deal but as you said for Home key issue, I would suggest you go on and develop the App as much as you need and the only final area you would get stuck is the home key control so, try to find some tricky way to get the control of home key and make it as an app launcher for your lock app. It is not very complicated but kinda tricky though. I will post you, if I can find any Home-key access source codes

PS:

Here is the tutorial for accessing home key

I found the home key override somewhere. Add these lines in the App Manifest.

Following two lines will do the magic

 <action android:name="android.intent.action.MAIN" />              
        <category android:name="android.intent.category.HOME" />                 
        <category android:name="android.intent.category.DEFAULT" />               

and override this method in your activity

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);           
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_HOME)
    {
        Log.i("Home Button","Clicked");
    }
    if(keyCode==KeyEvent.KEYCODE_BACK)
    {
        finish();
    }
    return false;
}

Keep in mind that I didn't test these codes or methods, just tried to help you (you might find some drawbacks).

PS: based on the votes I can guarantee that my suggestion is working and you can develop such app with the above help :)