Lock screen with user security password

I looked through a lot of similar questions, and I found that it is not possible to make Lock Screen as standard Android blockers. What is possible is to make an application that disables LockScreen and uses a different “lock” instead of the standard one. I am thinking of creating a special lockscreen with a different type of lock. What I don't know is possible:

  • Is there a way to use the .xml layout to lock the screen
  • Can I record it as a regular application.

I do not need links to existing applications on the market.

+6
source share
2 answers

I believe that you are right, because I also did not find a way to replace the original lockscreen. As you said, we can turn off the original and fake another.

I have a concept and you can also find this page: http://chandan-tech.blogspot.com/2010/10/handling-screen-lock-unlock-in-android.html

You turn off the original, add a listener to ACTION_SCREEN_ON, and as soon as it starts, show your fake lock screen, and now you can write it like a normal application, and I think the xml layout is absolutely practical.

To implement it, you must also perform the service and start it with the launch of the system. In your activity, you should also turn off the notification bar and buttons.

+1
source

You can try to override KeyguardManager

KeyguardManager.KeyguardLock key; KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE); //depreciated key=km.newKeyguardLock("IN"); 

You should insert this into service.Go something like:

 public class LockService extends Service{ BroadcastReceiver receiver; @override @SuppressWarnings("deprecation") public void onCreate(){ KeyguardManager.KeyguardLock key; KeyguardManager km=(KeyguardManager)getSystemService(KEYGUARD_SERVICE); //depreciated key=km.newKeyguardLock("IN"); IntentFilter filter=new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_BOOT_COMPLETED); receiver=new LockscreenReceiver(); registerReceiver(receiver,filter); super.onCreate(); } 

And then in LockscreenReceiver you have to perform this action:

 public class LockscreenReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context,Intent intent){ String action=intent.getAction(); //if the screen was recently enabled, do this: //If the screen was just turned on or it just booted up, start your Lock Activity if(action.equals(Intent.ACTION_SCREEN_OFF) || action.equals(Intent.ACTION_BOOT_COMPLETED)) { Intent i = new Intent(context, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } } 

you must register or call MainActivity

 startService(new Intent(this,LockscreenService.class)); 

To see this in action, go to https://github.com/thomasvidas/Simple-Lockscreen

0
source

Source: https://habr.com/ru/post/909891/


All Articles