Is there any way to retrieve position/location of android widget which is activated in android device, like whether its on lock screen, home screen etc. In lock screen is it the main widget displayed.
On Android 2.1 and later, with some select home screens, you can find out where an app widget resides when it is clicked via getSourceBounds() -- this value is attached to any Intent you spawn via a PendingIntent via setOnClickPendingIntent().
However:
this only works on Android 2.1 and newer
not all home screens might do this, as this is part of the Launcher code IIRC
the coordinates are in pixels IIRC
there is no way to interrogate the home screen to find out this information any other way, since there is no API to interact with the home screen
Hence, I think your stated goal ("Depending on whether it's on the top of the desktop or at the bottom different layouts for the widget will be chosen") is impossible, I think.
Related
I want to make a widget but it should be uninstallable or undeletable from home screen (if possible) like "google search" widget on nexus & moto phones. I searched it already but didn't find anything related to this. Is it really impossible to built such widgets?
Is it really impossible to built such widgets?
Yes. The decision of what widgets to allow users to add and remove is up to the home screen implementation, not you. So, for example, if on "nexus & moto phones" you install a third-party home screen, the Google search widget may or may not be available at all, let alone non-removable.
If you want to force people to have certain things on their home screen, write a home screen, then use heavy weaponry to force people to use that home screen. Note that the use of heavy weaponry may be illegal in some jurisdictions.
I know about offsetChange function, but it doesn't work on such devices as Galaxy S4. I think it happens because of TouchWiz wrapper. So I need to find out another way to determine count of home screens.
Any help will be appreciated!
Android has main screen like desktop.
Android has a home screen. Whether it is "like desktop" or not depends upon the device and user.
There are several home screens, you can switch between them
It is unclear what you mean by this.
You might mean "an Android device can have multiple applications installed that each offer to be a home screen, and the user can choose which of those applications to use". In that case, creating an Intent for ACTION_MAIN and CATEGORY_HOME, then passing that to queryIntentActivities() on PackageManager, should give you the list of possible home screen implementations.
You might mean "all Android home screens offer some sort of swiping option to move to different portions of space". Some home screens offer this, and there is no standard way to find out. There is no requirement that a home screen offer the capability of swiping this way, let alone a requirement to supply an API for third-party apps to find out details about them.
On say a Samsung Galaxy S3, it's possible via an application's manifest, to allow it to run in multi-screen mode. Thus when it is running, a second application can be dragged onto the screen and each application then has half (or may be different amounts) of the screen.
When an application is running full screen, how can it tell if another application has been dragged onto the screen, and thus it now only has half of the screen real estate?
The activity is not restarted, and the onConfigurationChange method is not invoked.
Section "3-8-9. Handling Layout Changes" in this document http://developer.samsung.com/s-pen-sdk/technical-docs-09 gives the answer.
Note, you don't need the Samsung SDK to detect the change.
I need a screen control (possibly but not mandatory an app widget) that will seat
on Android's homescreen and will always be visible to the user - even when he scrolls the homescreen to the next page.
Please help me if any body have done this before.
I think the only way you will be able to do this is if you implement your own Launcher.
The functionality that you're looking for, being able to place a static widget on every screen of the launcher regardless of how many screens they have, isn't currently available in Android, nor any of the launcher apps out there (Go launcher, ADW, Launcher pro etc) nor any of the versions of Android which have been rewritten by the phone manufacturers (HTC's Sense, Samsungs Touch Wiz etc)
It's a big job to write a Launcher yourself, but the stock Android Launcher code is available to play about with from https://android.googlesource.com.
I am developing an android widget to show in the homescreen. Now, I can show the widget in main homescreen. Now, is there any way to show that widget every homescreens (in most of the devices there are several homescreens where we can swipe to left or right from the homescreen)?
Only if the user manually adds your app widget multiple times.
These depends on entirely on the home screen app. Some home screen apps could certainly implement a UI to have a widget like this. The launcher that is part of stock Android does not have such a facility.