Launch android app on screen unlock

后端 未结 2 1674
无人共我
无人共我 2021-01-01 05:49

I want to build a lock screen replacement application. Is there any way to create a listener/service that would launch my app whenever the user wakes up/unlocks the screen?

2条回答
  •  一向
    一向 (楼主)
    2021-01-01 06:15

    See source code of mylockforandroid and you will need use DeviceAdminReceiver for disableing default android screenlock.

    for starting your activity when user unlock screen register an Intent.ACTION_SCREEN_ON and Intent.ACTION_SCREEN_OFF as:

    add this code in manifast.xml register ScreenReceiver as:

    
     
     
     
     
     
    

    and add an ScreenReceiver.java as:

     public class ScreenReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
             if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
             {
                Intent intent = new Intent();  
                intent.setClass(context, ScreenLockActivity.class);
                startActivity(intent);          
             }
        }
    }
    

提交回复
热议问题