1

There is an emergency app named Medical Id. It has a marvelous feature in which it shows notification on locked screen. The user can just double tap on the notification to open the activity. For other app notifications, if the user tap, it prompts for unlocking first. I am looking for the same feature but unable to achieve the same. I have tried adding flags to the attached windows.

@Override
    public void onAttachedToWindow()
    {
        super.onAttachedToWindow();
        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 &
                WindowManager.LayoutParams.FLAG_FULLSCREEN
        );
    }

Added shownonlockscreen to the activity in the manifest as well, But it prompts for unlocking the screen before opening the activity. Have a look on the medical id for clarity. I don't know what they are using to bypass unlock. The phone settings for notifications are public in my phone. The amazing part is even if your phone notification setting is private, medical id notification will be present there even when no else notification is present. Any leads is helpful.

AMAN SINGH
  • 3,491
  • 6
  • 28
  • 44
Raghav Sharma
  • 780
  • 10
  • 18
  • 1
    For Marshmallows devices you need to request permission for ScreenOverlay if you want to show your notification above the lock screen Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE); – Andy Developer Jun 07 '17 at 06:45
  • @AndyDeveloper can we have overlay notification? Overlay activity successfully bypasses lock screen using your above answer in marshmallow. In my case, clicking on notification still prompts for unlocking. I think if notification is also overlayed, it will work. Please share your thoughts . – Raghav Sharma Jun 07 '17 at 08:22
  • Nop it still ask you to unlock the screen. You can try DevicePolicyManager to lock and unlock device programmatically. Here is the developer site [reference](https://developer.android.com/guide/topics/admin/device-admin.html) and here is the stackoverflow [reference](https://stackoverflow.com/a/14352807/5860777). Hope this will help you. – Andy Developer Jun 07 '17 at 09:01

2 Answers2

0

You should use pipes | instead of ampersands &

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

Also this only works above Android 4.4

moritzg
  • 4,266
  • 3
  • 37
  • 62
0

if you want to show Activity on click of your notification from lock screen, you can do like this in OnCreate of your Activity lifecycle

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setTurnScreenOn(true);
        setShowWhenLocked(true);
    } else {
        window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
    }
}
Hasif Seyd
  • 1,686
  • 12
  • 19