1

I'm trying to make a custom lock screen app, but I'm not sure if I'm going about it the right way. I have a broadcast receiver that listens to when the screen is turned on and starts my lock screen activity. This receiver is registered inside a service, which also disables the default lock screen.

The problem is, there is a slight delay between when the screen is turned on and the lock screen activity shows up. How would I go about doing it so that it shows up right away?

My code for the service:

@Override
public void onCreate() {
    super.onCreate();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    BroadcastReceiver powerReceiver = new PowerReceiver();
    registerReceiver(powerReceiver, filter);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {  

    KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Service.KEYGUARD_SERVICE);
    KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
    lock.disableKeyguard();

    return Service.START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

and the receiver:

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
        Intent showScreen = new Intent(context, LockScreen.class);
        showScreen.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(showScreen);


    }   

}
CoffeeCrisp
  • 253
  • 3
  • 6
  • 19

1 Answers1

0

Turn your app into a home screen replacement app and when the user successfully unlocks the custom lock screen you can take them to the default home app.

You can find more info in this question and these questions.

Community
  • 1
  • 1
Luke
  • 1,069
  • 18
  • 28
  • 1
    Thanks but how do i redirect them to the default homescreen after unlocking? If i use an implicit intent, then if they set my lock screen as the default homescreen, they would just go back to the lock screen? I tried intent.setClassName("com.android.launcher", "com.android.launcher2.Launcher"); which just gives me an error – CoffeeCrisp Nov 16 '12 at 16:07
  • Already tried that, and it gives me the "complete action using" prompt unless i choose the default. Does the user have to choose their original homescreen as the default app? Then how would I get the lock screen to show up in the first place? – CoffeeCrisp Nov 16 '12 at 16:27
  • Your lock screen needs to be the default home application. I'm not 100% sure how other people are getting the launchers to show after the unlock of a custom lock screen – Luke Nov 16 '12 at 16:48
  • 1
    Figured it out! Gotta disable the manifest intent filter by using setComponentEnabledSetting(), and then turn it back on when the activity pops up. Thanks for your help! – CoffeeCrisp Nov 16 '12 at 19:05
  • Hey CoffeeCrisp, can you please explain how you accomplished this? I would love to know as well. I also receive a delay between the screen on and activity start. – user1190019 Dec 22 '12 at 05:22
  • @CoffeeCrisp so finally you went ahead with your approach or used the homescreen replacement app? – Dev Dreamer Apr 14 '13 at 21:40
  • @Luke, can you please help me with this: http://stackoverflow.com/questions/16089525/understanding-custom-lock-implementation-on-android-via-home-screen-replacement (I'll highly appreciate any help). Thanks. – Dev Dreamer Apr 18 '13 at 17:50
  • @Luke your answer is very helpful. i have make home screen replacement app successfully.. but how can i take user to default home screen(after unlocking)? can you describe more about this. Thank You so much... – Sanket Kachhela May 15 '13 at 08:03
  • I've never actually implemented it, I would take a look at `setComponentEnabledSetting()` – Luke May 17 '13 at 18:42
  • hello @CoffeeCrisp i have successfully implemented lock screen as home screen replacement app. and i also targeting default home screen after unlocking logic by using setComponentEnabledSetting() as Luke described . but this is working for me till i unlock once. means if i unlock first time than after not getting custom lock screen.. any help? thanks... – Sanket Kachhela May 28 '13 at 11:42