Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make our own lock screen in android instead of default lock screen [duplicate]

I have an idea of creating my own phone lock app similar to android pattern lock. I need to display or start my app whenever the phone boots/restarts/phone, lock/phone, and unlock. I don't know how to make the app appear instead of default lock screen and to hide the default lock screen. So my questions are:

  1. How to display or start my app instead of default lock screen
  2. What is

    getWindow().addFlags(
      WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | 
      WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | 
      WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | 
      WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    

How this is helpful?

  1. What is

    public class BootReciever extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction() != null) {
                if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
                Intent s = new  Intent(context,ViewPagerMainActivity.class);
                s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(s);
                }
            }
        }
    }
    

How this is helpful?

  1. How do you show the home page after my app finishes its work?
like image 907
SreBalaji Thirumalai Avatar asked Jul 06 '14 17:07

SreBalaji Thirumalai


1 Answers

Codes that you have used in point 2 should be used as answer of your question 1. Reference is Android activity over default lock screen.

For question 2, see these relevant links:

  • WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  • WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
  • WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
  • WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON

Before answering your question 3,i would like to ask you, do you have knowledge about BroadcastReceiver? In short it is-

A broadcast receiver (short receiver) is an Android component which allows you to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens.

For example, applications can register for the ACTION_BOOT_COMPLETED system event which is fired once the Android system has completed the boot process.

Now come to your question 4, you can show home page programmatically by this code:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

Refer: Going to home screen programmatically

And last of all i would like to provide you some links that may help you to make a custom lock screen:

  • Creating an Android Lock Screen App.
  • Any tutorial for customize lock screen in Android
  • Making Customize Lock Screen
  • Implement lock screen in Android
like image 149
ridoy Avatar answered Oct 13 '22 12:10

ridoy