getting battery level at android widget

岁酱吖の 提交于 2019-12-04 02:55:21

hackbod gave the solution at the comments:

" use getApplicationContext().registerReciever() "

Ummmm...that feels like a bug. They must be doing the is-a-BroadcastRecevier check too soon. You might want to create a project that demonstrates the problem, then post that to b.android.com.

In terms of a workaround:

Step #1: Create an IntentService

Step #2: In onHandleIntent(), do your actual widget update work, including getting the battery level

Step #3: Have onUpdate() of your AppWidgetProvider just call startService() on your IntentService.

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