Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch android app on screen unlock

Tags:

java

android

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?

like image 435
Peter Avatar asked Jun 23 '12 20:06

Peter


1 Answers

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:

<receiver android:name=".ScreenReceiver">
 <intent-filter>
 <action android:name="android.intent.action.SCREEN_OFF"/>
 <action android:name="android.intent.action.SCREEN_ON"/>
 </intent-filter>
 </receiver>

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);          
         }
    }
}
like image 65
ρяσѕρєя K Avatar answered Sep 27 '22 21:09

ρяσѕρєя K