简体   繁体   中英

Launch android app on screen unlock

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?

I believe you are looking for the ACTION_USER_PRESENT intent action.

public static final String ACTION_USER_PRESENT

Since: API Level 3 Broadcast Action: Sent when the user is present after device wakes up (eg when the keyguard is gone).

That said, Android does not support replacing the lock screen at this time. Any apps on the market that claim to do this make use of security loop holes and are not secure. You can read this thread for more information. (in particular, you should read Mark Murphy's posts). Sorry.

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);          
         }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM