I want my activity to appear in the list of activities (gallery. live wallpapers, etc) that you see when you try to choose a wallpaper from the home screen.
Im assuming this is done with intents but cant seem to find one that works. The closes开发者_StackOverflow中文版t one I can find is:
<action android:name="android.intent.action.ACTION_SET_WALLPAPER>
but that doesn't work and seems to be used for something else.
This should be the intent-filter you want:
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Defined here: http://developer.android.com/reference/android/content/Intent.html#ACTION_SET_WALLPAPER
(The DEFAULT category is a standard syntax for intents.)
The list under 'select wallpaper from' dialogue box that pops up when you click 'wallpapers' from the homescreen has three entries on most phones (I checked stock and HTC Sense):
- Live wallpapers
- Gallery
- Wallpapers (or: HTC wallpapers)
When I press 'wallpapers' from the homescreen on HTC Sense I get:
09-26 20:17:58.901: INFO/ActivityManager(104): Starting activity: Intent { act=android.intent.action.SET_WALLPAPER_DIALOG cmp=com.htc.launcher/.WallpaperChooserDialog (has extras) }
09-26 20:17:59.301: INFO/ActivityManager(104): Displayed activity com.htc.launcher/.WallpaperChooserDialog: 353 ms (total 353 ms)
When on stock:
09-26 20:19:41.231: INFO/ActivityManager(86): Starting activity: Intent { act=android.intent.action.CHOOSER cmp=android/com.android.internal.app.ChooserActivity (has extras) }
09-26 20:19:41.571: INFO/ActivityManager(86): Displayed activity android/com.android.internal.app.ChooserActivity: 294 ms (total 294 ms)
And when I click through on 'wallpapers' when on stock:
09-26 20:19:51.101: INFO/ActivityManager(86): Starting activity: Intent { act=android.intent.action.SET_WALLPAPER flg=0x3000000 cmp=com.android.launcher/com.android.launcher2.WallpaperChooser }
09-26 20:19:51.581: INFO/ActivityManager(86): Displayed activity com.android.launcher/com.android.launcher2.WallpaperChooser: 463 ms (total 463 ms)
You need to use android.intent.action.SET_WALLPAPER. Maybe you forgot some other implementation details such as
<category android:name="android.intent.category.DEFAULT" />
so the chooser could pick it up? Have a look at Photostream's source code (http://code.google.com/p/apps-for-android/source/browse/trunk/#trunk/Photostream). Romain Guy has it working.
Basically, you can not set activities as a wallpaper. You have to create a Live Wallpaper
instead, and draw your content on a SurfaceView
using a Canvas
. You may create views yourself there in order to draw them on the canvas manually, but that is a little tricky and in most of the cases not what you want.
精彩评论