Android: programmatically get position of the widget on desktop relative to other widgets

北城以北 提交于 2019-12-05 20:39:35

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!