Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show dialog with touch events over lockscreen in Android 2.3

I want to build a dialog which is visible on the lockscreen and can receive touch events. I built a window with WindowManager but only the TYPE_SYSTEM_OVERLAY Flag is shown over the lockscreen in GB (Android 2.3.7).

Is there a way to create a system overlay which is visible on the lockscreen and can receive touch events in Android 2.3.7?

There was a bug with FLAG_WATCH_OUTSIDE_TOUCH but I'm not sure how that affects me. Any ideas?

like image 674
Cilenco Avatar asked Jun 23 '13 13:06

Cilenco


3 Answers

I do not think you can launch an activity each time when device is locked without binding your application as admin privilaged app programatically.

Once your app is admin privilaged app, you can programatically set password & lock the screen & then programatically unlock it using Device Policy Manager.

On top of that lock screen you can programatically launch your own activity & you can create your own unlocker & unlock device through that activity as you can get call backs via DeviceAdminReceiver.

Here is a good example for that & all you need is to create your own activity after you called DevicePolicyManager.lockNow(). Then it will appear on top of lock screen as normal activity plus extra control over native lockscreen.

like image 197
M P Mathugama Avatar answered Nov 14 '22 07:11

M P Mathugama


Try this It may helps you,

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.alertdialog);

And also, Android is a little bit of a contradiction. It's very open and as a developer you have access to anything, and it's up to you to use those powers for good or evil. When I say evil I don't mean malware. I mean apps that try to get cute and use things in ways they weren't meant to be used, like putting up notifications asking you to use the app more. The contradiction is that you don't actually have access to everything, there are a few parts the developers decided were so important that app couldn't mess with them. The lock screen is one of those parts. You can replace your home app all you want, but you never have to worry about your replacement lock screen failing and preventing you from accessing your phone.

Even if this were possible you would have more problems to deal with. Every lock screen is different, manufacturers can and do customize it so you have no guarantees your activity won't get in the way of unlocking the phone.

For touching outside of your dialog,

dialog.setCanceledOnTouchOutside(your boolean);
like image 39
No_Rulz Avatar answered Nov 14 '22 07:11

No_Rulz


Finally I achieved the same. Don't go for activity, because android will not show lock screen behind your activity for security reason, so for service.

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);
like image 1
Shirish Herwade Avatar answered Nov 14 '22 07:11

Shirish Herwade