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.
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 want to know if the user clicks on the Home button (like listen to Home button).
Because I saw that is there now way to do that, I tough about an idea.
Maybe if I will create a launcher I will be able to handle to Home button...
But since I don't want to really create a launcher, so I want to create a launcher, that opens the previous one.
How can I create such a launcher? Or is it possible to use BroadcaseReceiver to listen to Home button?
HOME button can not be monitored nor reacted to and there is no workaround.
As for the launcher:
First, you would need to fetch the ResolveInfo for the current launcher and keep its package name somewhere, like SharedPreferences.
Later, the user would have to accept your launcher as the default launcher. After that, you should make your launcher's onCreate() method's only job to create an intent which will open the previously saved package and then immediately call finish() on your launcher.
However, I am pretty sure you will stumble upon some problem along the way, as this is Android. Anyway, be my guest to try and post the result here, the concept is really interesting.
I have created the widget, but this widget does not show directly on the home screen, I want it to be displayed directly on the home screen, immediately after the application is deployed, like a shortcut, and clicking on the shortcut widget will go to the application
Can someone suggest me?
Thanks
I want it to be displayed directly on the home screen, immediately after the application is deployed
You cannot run any code at the time the user installs your application. You must wait for them to launch it, or in the case of a home screen widget you must wait for them to explicitly place it on the home screen.
You have to add an intent line to your manifest that exposes the action you want to do through a shortcut.
see: http://android-developers.blogspot.sg/2009/11/integrating-application-with-intents.html?m=1
I would like to handle the volume up and volume down keyEvents in my App Widget.
It really should happen in the app widget or a Service, not in an Activity (the homescreen should be displayed).
But as far as i know there don't seems to be a possibility to react with the user from an app widget or service, so i can't get the keyEvents.
So my Question is if I'm wrong and there is a possibility to get the keyEvents or maybe one to make the acitivity invisible?
If by "Widget" you mean "app widget", then, no, you cannot respond to key events from an app widget.
I have found a trick. It's not really the best, but in my case I can use it.
With assigning the themes
android:theme="#android:style/Theme.Dialog"
or
android:theme="#android:style/Theme.Translucent.NoTitleBar"
in the Android Manifest, it's possible to have an Activity that looks like an Dialog or which is transparent. So the home screen is visible and in the Activity I can get the keyEvents.
Although it isn't possible that the user can interact with the home screen during the activity is running, but in my case this isn't needed necessarily.
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?