Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, How to launch Activity over Lock screen

Tags:

android

I want launch my activity on push notification over lock screen without change in lock.

Any special permission for that activity?

like image 434
Palak Avatar asked Feb 12 '16 07:02

Palak


People also ask

How wake up device and show an activity on top of lock screen for alarm?

Update: If you want to show the Activity on the lock screen, you need to set showForAllUsers to true. Here's the description from the Android documentation: Specify that an Activity should be shown even if the current/foreground user is different from the user of the Activity. This will also force the android.

How do I run Android apps on my lock screen?

Here's how to open your favorite apps directly from the Lock screen on your Galaxy device: Go to Settings > Lock screen > Shortcuts. Tap Left shortcut and pick your desired app.


2 Answers

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1)
    {
        setShowWhenLocked(true);
        setTurnScreenOn(true);
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        if(keyguardManager!=null)
            keyguardManager.requestDismissKeyguard(this, null);
    }
    else 
    {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }
like image 164
Vladimir Demirev Avatar answered Oct 16 '22 21:10

Vladimir Demirev


After API level 17 this would work

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

or write this in onCreate() before calling setContentView()

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); 
like image 31
Ravi Avatar answered Oct 16 '22 21:10

Ravi