Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity over default lock screen

How can I display an Activity or Dialog to be visible over the lock screen?

I have already tried displaying my lock activity when screen turns on by setting various window type in Activity.onCreate() method:

TYPE_PRIORITY_PHONE
TYPE_SYSTEM_ALERT
TYPE_KEYGUARD

and others together with SYSTEM_ALERT_WINDOW and INTERNAL_SYSTEM_WINDOW permissions.

My activity is visible after I unlock the device.

UPDATE:

I actually already managed to display my own Activity instead of default lock screen. It work perfectly unless you use HOME button.

like image 427
plugmind Avatar asked Sep 02 '10 16:09

plugmind


2 Answers

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

try using this flags to disable lock screen when the activity is started.

After API level 17 you can use

<activity         android:name=".yourActivityName"         android:showOnLockScreen="true"         android:screenOrientation="sensorPortrait" > 

showOnLockScreen like in the example...

like image 161
Enes Avatar answered Sep 23 '22 15:09

Enes


Don't go for activity, because android will not show lock screen behind your activity for security reason, so use service instead of Activity.

Below is my code in onStartCommand of my service.

WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);  View mView = mInflater.inflate(R.layout.score, null);  WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED     | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD     | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON /* | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON */, PixelFormat.RGBA_8888);  mWindowManager.addView(mView, mLayoutParams); 

And add <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> to manifest

like image 33
Shirish Herwade Avatar answered Sep 21 '22 15:09

Shirish Herwade