All packages that respond to a certain category on Android?
I want to build an Android widget that will update very frequently (5 seconds). This means, I want to only update it when the screen is on and when the home screen is the active Activity.
How do I get a list of home apps (or apps that respond to
<category android:name="android.intent.category.HOME"/>
)
In the android API, can I use Intent.createChooser(Intent target, CharSequence t开发者_Go百科itle)
and somehow get the list or do I have to get all activities, retrieve their Intents and use hasCategory(String category)
on every Intent.
Thanks!
I want to build an Android widget that will update very frequently (5 seconds).
Ick. Please allow this to be configurable by the user.
This means, I want to only update it when the screen is on and when the home screen is the active Activity.
I wouldn't worry about the screen being on -- just use a non-_WAKEUP
alarm with AlarmManager
. However, the "when the home screen is the active Activity" is going to be an epic hack if it works at all.
In the android API, can I use Intent.createChooser(Intent target, CharSequence title) and somehow get the list or do I have to get all activities, retrieve their Intents and use hasCategory(String category) on every Intent.
Use queryIntentActivities()
for an ACTION_MAIN
/CATEGORY_HOME
Intent
.
Then, you will run into the problem of that these activities are merely the entry points for the home screen and may or may not be the ones that actually display the home screen itself.
Then, you will run into the problem of determining if this is the activity that is on the screen. I don't know if that is possible. ActivityManager
, for example, will tell you if it is running (answer: 100% of the time), but I do not see where it has the notion of one being on the screen and others not.
Then, you will run into the problem of where even the ActivityManager
APIs that exist are not event-driven, meaning you will still need to be running your code to poll the ActivityManager
, though you may be able to save a few instructions by skipping work if you somehow determine the home screen is not in the foreground.
Hence, I go back to "please allow this to be configurable by the user", since you are just begging for one-star ratings on the Market, particularly depending on what you intend to do every 5 seconds.
See my answer to this question: Android - how update widget often but only when it is visible?
精彩评论