How to create my own lock screen widget (I just want to display a button)

I need to allow users to quickly capture an image using my application when the device is locked. I believe that the fastest way for the user to do this is through a button / widget on the lock screen - although I'm not sure how to do it.

Most of the links I found are related to playing music and using RemoteControlClient (can it only be Android 4.4?). He has the most basic thing, I would just press one button that says β€œcapture”. Any help on how to do this?

+8
android android-intent
source share
1 answer

API Levels

Lock widgets were introduced in API 17 (4.2) and removed in API 21 (5.0). They are not supported in other official releases.


Main widget

I wrote a simple widget as a demo tutorial - it contains all the template code needed for the widget, and quite a bit:

I wrote it in such a way that every user can delete the wifi code associated with it and adapt it to their requirements for widgets. It may be ideal for you to watch, and relatively simple to add one button to it.


Keypad Lock / Lock Widget

There are two changes to make it work as a lock widget:

  • widgetCategory update to enable keyguard
  • adding initialKeyguardLayout

These changes are made in the ./res/xml/widget_info.xml file, as shown below:

 <?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialKeyguardLayout="@layout/widget" android:initialLayout="@layout/widget" android:minHeight="40dp" android:minWidth="250dp" android:updatePeriodMillis="0" android:widgetCategory="home_screen|keyguard" > </appwidget-provider> 

I do not know if it is possible to integrate the camera into my own lock widget. Clicking on the lock screen widget usually requires the user to unlock the device before clicking.

+11
source share

All Articles