Is there an Event that is fired when an widget becomes visible on to the homescreen. I didn't mean at install time, I mean if the user changes his homescreen by wiping the surface of the phone.
The background of this question is that I setup a timer in a service inside the widget that gets updates from a url but that should stop if the widget is not on the current homescreen.
Freudi
There is a way to do that, you can listen to Intent.ACTION_USER_PRESENT broadcast and update your widget on receiving the intent.
It will be fired when the user unlocks the home screen.
I am using it in my app and works great to update your widgets upon unlock.
No, sorry. There are dozens of home screen applications, some of whom may not even have the concept of "wiping the surface of the phone". A home screen is merely an activity with a particular <intent-filter>.
Not sure if this helps, but I stumbled across this..
WallpaperManager.setWallpaperOffsets() and WallpaperService.onOffsetChanged()
Perhaps you could use this? Set wallpaper offsets and use onOffsetChanged() to get current offsets?
Related
I'm trying to display a view that the user must dismiss each time they unlock their phone (it's intended to be annoying). It should be able to take a small amount of keyboard input, save it, then return to the previously open activity. I tried having a BroadcastReceiver listen for ACTION_USER_PRESENT and launch my own activity, but then I found out we can no longer listen for implicit intents, or have background services launch activities.
I'm not an Android developer (just trying to build something for my phone), but I did some looking, and I see a few options:
Display a full-screen intent. I think something like scheduling a job to raise a notification whenever the phone is locked, so that the notification appears first thing when they unlock the phone.
Use SYSTEM_ALERT_WINDOW and draw my view as an overlay whenever the phone is unlocked. My only concern with this is how apps like Twilight (which I believe draws an overlay to redden the screen) might interact with it. In those cases, I'd like my overlay to appear at the very bottom.
Are either of those options viable or recommended? Any other suggestions or approaches for how I could accomplish this would be greatly appreciated too. I'm just looking for some guidance on what direction I should pursue.
I have a widget and I want to auto-update it on one occasion only and that is when the user unlocks his phone. This is a requirement I have and it is not negotiable.
So how do I do that? How can I make sure that I get any callback of any kind when the user unlocks the screen. The update of the widget does not need to be instant. It is enough if it updates a couple of seconds after the screen is unlocked.
Is this possible?
Thanks
Did you try to use https://developer.android.com/reference/android/content/Intent#ACTION_USER_PRESENT
You can try to use BroadcastReceiver that listens for this event and then update your widget
I developed an APP + Home screen widget for Android. Now I updated the app (incremented the version code/name) but when i install, it doesn't automatically replaces the existing widget on screen. It just says "problem loading widget".
Any Idea??
Did you change the class name of the broadcast receiver implementing your widget? If so, don't do that.
There is of course the related use-case where there was a widget loaded on the home page and the user then uninstalls the application that contains the widget and widget config app. I guess this is the same as a new version which must to an uninstall/install cycle.
When that happens, all you see is the "Problem Loading Widget" in a toast-like box on the home screen. As far as I can tell, the widget gets no indicatation that the package is being uninstalled and I guess then the home screen AppWidgetManager thows up a default message.
Not well thought out behaviour on the part of the OS team. I suggest that it would be better to call the widget's onDisbled() and onDestroy() methods and to remove the widgets from the home screen before the package is removed so they can tidy up if need be and the user (non-geek phone user) gets a clean experience.
All I can find is the indication that only the user can remove a widget from the home screen, says commonsguy: Removing AppWidgets programmatically
I sure us developers can handle the odd weird toast, but for non technical "ordinary" phone users this sort of behaviour drives them back to iPhones very quickly.
This is the right behavior to me. As app is installed again, its widgets should be installed again too. If, for instance, there is a new activity to configure the widget, how do you know it as a user ?
There is, indeed, no way to guarantee that a new widget would run at all from this perspective.
When a user presses a shortcut on the screen and that shortcut starts up an activity, how can I get the location of where the shortcut is on the screen?
I have the same question for a widget. When a user has a widget on the screen and pressing it fires off the setOnClickPendingIntent how can I know the location on the screen where the widget is?
In both scenarios there is no View to run View.getLocationOnScreen.
When a user presses a shortcut on the screen and that shortcut starts up an activity, how can I get the location of where the shortcut is on the screen?
You can't, sorry.
When a user has a widget on the screen and pressing it fires off the setOnClickPendingIntent how can I know the location on the screen where the widget is?
You can't, sorry.
The only way to get any of that would be to write your own home screen, where you are handling the shortcut presses and app widget taps.
EDIT: The way the QuickContactActivity achieves the effect described in the comments is via getSourceBounds(), a method on Intent. This Rect may or may not be available on any given Intent, and therefore any code looking to use it should be able to cleanly react to an Intent that has no such value. I can see where RemoteViews, the basis for app widgets, use it. I am having a bit more difficulty seeing under what other circumstances the Launcher application uses it. Bear in mind that not all home screens may elect to use it. I apologize for my erroneous original answer.
the problem is that once a widget of my application is uninstalled, it lkeaves a black message box on the home screen saying unable to load widget, i was wonderring if we could clean the system display our self, is it possbile to add some code/ call to instruct the android frame work to do that, the widget is being consumed by a remote service may be once service is finished/closed we can call some syetem calls, any code for helping out the home reloading will help, Thanks
There is nothing for you to do. The user and the home screen will take care of this.