30

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 :-)

Kirk
  • 4,957
  • 2
  • 32
  • 59
user3047494
  • 429
  • 1
  • 6
  • 14
  • Well I figured there would be some kind of hint how hard this is, I mean for example theres an unruly amount on the market place, making me believe there are quite a certain number of developers who can, which you would go on to believe their would be some sort of tutorial! – user3047494 Jan 06 '14 at 05:28
  • Check this link... http://forum.xda-developers.com/showthread.php?t=1754753 – Talha Q Jan 06 '14 at 05:28
  • A screen that could really disable switching out would be a horrible security flaw. – chrylis -cautiouslyoptimistic- Jan 06 '14 at 06:04
  • Yes I have already done this kind of project, it's very much possible. There needs manifest permission as well as bootupreceiver and few more things. If you would like code, then inform me. – Satyaki Mukherjee Jan 06 '14 at 06:27
  • You may check my answer, I think will help you achieve what you want http://stackoverflow.com/a/28603790/3300883 – Miguel Feb 19 '15 at 10:28
  • 2
    @SatyakiMukherjee can you share your source code? – baldguy Dec 11 '16 at 04:05

1 Answers1

37

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 :)

Kirk
  • 4,957
  • 2
  • 32
  • 59
  • 3
    The home key solution is partly working. It will override the home button only if the user will agree to define your app as the callback app for this action. – Mugen Jul 23 '14 at 11:18
  • Yes sir, every action we do within the android app only after the approval of the user! i don't think it is a big deal? – Kirk Jul 23 '14 at 11:55
  • Well, you don't need the user's approval in order to override the 'back' button. The user will think that my app can control the 'home' button on its own and won't expect it to ask me to choose which app should control the home button.. – Mugen Jul 23 '14 at 12:57
  • Just use the [Adenda SDK](http://adendamedia.com). It essentially extends the standard Android libraries to make things simpler on you – Cigogne Eveillée Apr 06 '15 at 22:24
  • @CigogneEveillee http://www.adendamedia.com/#intro do they provide sdk or app i have found their app which is paid how u use it ? can u pls explain – Erum May 06 '15 at 07:24
  • @Kirk Is this possible for the latest API 28 & 29? – Deepak Kumar Sep 25 '19 at 08:22