1

As there is an exciting feature in Android 4.2 to place app widget on Lock-Screen. I have implemented it for my app, but I have to choose my widget to enable it on lock screen.

But I want to enable and disable widget from my app. That is, if user click on check-box then automatically widget for that app should enable on lock-screen and is user un-check then automatically widget will disable from lock-screen.

please help me.

  • As far as I know, you can't change the manifest at runtime. You could make the widget unusuable, but not inaccessible at runtime... – tilpner Jun 13 '13 at 13:59
  • @StackOverflowException actually you can enable / disable components in the manifest using code: http://stackoverflow.com/questions/5624470/enable-and-disable-a-broadcast-receiver – Richard Le Mesurier May 16 '14 at 13:57
  • @RichardLeMesurier: Oh, that's interesting to know, thank you. :) – tilpner May 16 '14 at 15:08
  • @RichardLeMesurier or anyone else - are there any examples for how to adapt http://stackoverflow.com/questions/5624470 to lock-screen widgets? I know it's possible because the Amazon Prime app dynamically adds a player widget to the lock screen while playing. Thanks! – cxw May 15 '15 at 20:01

2 Answers2

0

For folks finding this via Google, there are some workarounds that may work for you or may not, depending on your specific Android configuration. (See also this question and this question.)

As CommonsWare pointed out, beginning with Android 5.0, a media style notification can be dynamically added to the lock screen.

Community
  • 1
  • 1
cxw
  • 16,685
  • 2
  • 45
  • 81
-1

This is not possible. The user is welcome to add your lockscreen widget if the user chooses to, from the lockscreen.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • As for adding lock screen widget we have to choose it from lock-screen only. Is there be any Intent that help user to add widget to lock-screen. Or can we use that intent to do this? – user2075364 Jun 13 '13 at 14:03
  • @user2075364: "Is there be any Intent that help user to add widget to lock-screen" -- none that I am aware of, just as there is no such `Intent` for helping a user add an app widget to the home screen. – CommonsWare Jun 13 '13 at 14:07
  • Sir is there be any other means to do this, because my app is based on on this only. – user2075364 Jun 14 '13 at 12:23
  • 2
    @user2075364: As I wrote, **this is not possible**. – CommonsWare Jun 14 '13 at 12:27
  • Sir can we used any alternative approach for this. I had work on to create an separate activity that get's called on device unlock and device boot-up. I had kept the background of this to transparent but background is not visible correctly. – user2075364 Jun 17 '13 at 13:20
  • Commons, has this changed since you originally answered the question? The Amazon Prime app now dynamically adds a player widget to the lock screen while playing. Thanks! – cxw May 15 '15 at 20:01
  • 1
    @cxw: I doubt it. Most likely, that's the media controller (managed by `MediaControlClient`) or a `MediaStyle` lockscreen `Notification`. The latter is new to Android 5.0+, with the former approach deprecated. Many media players use these. – CommonsWare May 15 '15 at 21:03