Android ICS native lockscreen

大兔子大兔子 提交于 2019-11-30 05:25:22

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!