6

I've been looking for the past 2 days on SW, google and so on. I'm looking for a way to implement an activity that comes with the native Android ICS lockscreen as the one shown in the screens below. Those screens come from Player Pro but I noticed that also other players ( PlayerPro for instance ) have the same feature that looks exactly the same, that's why i think it's something native or at least, there is a common way to implement it.

So far I only managed to get and Activity that replace the lockscreen using these flags:

  • WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  • WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD

with a BroadCaseReciever on these events:

  • Intent.ACTION_SCREEN_ON
  • Intent.ACTION_SCREEN_OFF
  • Intent.ACTION_USER_PRESENT

My problem is that i want my activity to be shown with the lockscreen not replacing it. Do you guys know how to achieve this?

is there a native-hidden API to do this?

can you guys link me some sample that implement this particular feature?

thanks in advance ;)

enter image description here enter image description here enter image description here

Mario Lenci
  • 10,422
  • 5
  • 39
  • 50
  • See this post : http://stackoverflow.com/questions/4065201/android-how-can-i-programmatically-draw-text-on-key-guard-screen-lock-screen But, maybe since the 4.0 it's possible, else Player Pro use its own API – Guillaume May 29 '12 at 15:18
  • what do you mean with "its own API"? by the way also other players have the same feature ( PowerAmp for instance ) so i guess it's not something developed by the PlayerPro guys. – Mario Lenci May 29 '12 at 19:13
  • Is it maybe a dialog fragment using the show when locked flag? EDIT: there also appears to be a FLAG_SPLIT_TOUCH that allows touches outside the window to be transferred to that window if it has the flag on... Seems like the combination of these two could allow it – Drake Clarris May 29 '12 at 20:55
  • well, I've tried and I can't get it working because I can't show a dialog from a BroadCastReciever, it gives this error "BadTockenException: Unable to add window -- token null is not for an application". Do you know how to retrieve the lockscreen token? that would be the solution. – Mario Lenci May 30 '12 at 07:40
  • I also tried to use FLAG_SPLIT_TOUCH in my activity using the Dialog style but still, it doesn't work because as soon as I set "android:windowIsFloating" to true the activity is shown after the lockscreen. And without it does't show in overlay of the lockscreen. other ideas? – Mario Lenci May 30 '12 at 07:46

2 Answers2

7

I think you might be looking for the Audio Controls "remote view" (RemoteControlClient) API added in Android 4.0 (API level 14). I found the RemoteControlClient API in the Android developer docs that:

enables exposing information meant to be consumed by remote controls capable of displaying metadata, artwork and media transport control buttons.

(It was linked off of this page.)

Note: I have never used this API myself, so I apologize if this does not work for you.

scorpiodawg
  • 5,612
  • 3
  • 42
  • 62
  • +1 This is definitely what he's looking for, and what he should use for native integration with the lock screen. – Kevin Coppock Jun 08 '12 at 18:07
  • yeee... finally the answer i was looking for. +1 and bounty. I knew there was an API but i couldn't find it. Thanks a lot I m so happy i can finally implement that lockscreen :D. – Mario Lenci Jun 11 '12 at 08:23
  • Note: Sample is no longer available in the Developer portal. – radley Jul 26 '14 at 01:24
1

You're almost doing it right. Keep doing what you do with the BroadcastReceiver. That's the way to go. For the Window, these are the flags you need to use:

  • WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  • WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL

Do not use FLAG_DISMISS_KEYGAURD

What these flags do: SHOW_WHEN_LOCKED allows your activity to show up on top of the lock screen. FLAG_NOT_TOUCH_MODAL allows touch events that are not on your activity to go to the other activities, ie, allows the user to unlock the screen. FLAG_DISMISS_KEYGUARD gets rid of the lock screen, so we do not use it.

Define this style in your res/values/styles.xml file

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.FloatingTranslucent" parent="android:Theme.Translucent.NoTitleBar">
    <item name="android:windowIsFloating">true</item>
  </style>
</resources>

In your manifest, define your activity's style

<activity android:name=".SampleActivity" android:theme="@style/Theme.FloatingTranslucent">
...
</activity>

What this does is makes your activity completely see through and wrap content.

Now, your activity should be on top of the lock screen, allowing touch input to the lock screen and to your app, with your activity not full size.

Cheers.

Zaid Daghestani
  • 8,555
  • 3
  • 34
  • 44
  • did you already implement it that way? because i tried and as soon as i put android:windowIsFloating to true i can't get the Activity to show on top of the keyguard, even if i set FLAG_SHOW_WHEN_LOCKED – Mario Lenci Jun 05 '12 at 09:53
  • i also tried to put TYPE_KEYGUARD_DIALOG as window type but nothing changed. – Mario Lenci Jun 06 '12 at 10:42
  • Hello @Zaid-Daghestani would you have a solution for this? http://stackoverflow.com/questions/33466950/creating-a-real-lockscreen-module-for-android – Rafael Ruiz Muñoz Nov 01 '15 at 21:14