1

I have a livewallpaper and I want to my wallpaper work in portrait mode only. Can I do it?

<application
        android:label="@string/wallpaper_name"
        android:debuggable="true"
        android:screenOrientation="portrait"
        android:icon="@drawable/icon">
        <service
            android:label="@string/wallpaper"
            android:name=".LiveWallpaper"
            android:permission="android.permission.BIND_WALLPAPER">
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data 
                android:name="android.service.wallpaper" 
                android:resource="@xml/weather_wallpaper" />
        </service>
</application>

I try this, but it does't work, because there is not android:screenOrientation in application tag.

George
  • 1,327
  • 11
  • 25

1 Answers1

2

I'm a little puzzled by your question: by default, live wallpapers generally remain locked in portrait mode, to correspond to the behavior of the default launcher. Are you saying that your wallpaper is automatically shifting into landscape mode when you rotate the phone? If that's true, please tell us:
1) Do the live wallpapers that came with your phone (Polar Clock, Grass, Cube from SDK, etc.) shift into landscape mode when you rotate your phone, too?
2) Are you using a custom launcher? Do its icons/widgets rotate when you rotate your phone?
Please let us know and we'll try to help. :-)

Edit: I have not seen this spelled out clearly anywhere in black and white, but my impression is that we live wallpaperers are generally at the mercy of the launcher being used. As previously mentioned, most devices come with launchers that do not respond to orientation changes, so the surface they give you doesn't either. I know some custom launchers do respond to orientation changes, but I did not realize until puzzling out your question that the emulator's launcher does, too. My best guess is that you cannot prevent a custom launcher (including the emulator) from rotating your canvas. However, you can detect and compensate for this, if you want. In onSurfaceChanged, you can check if your width is greater than your height, and if it is, you can query the orientation using the technique shown here: http://www.codeproject.com/KB/android/AndroidLiveWallpaper.aspx
Then you can just rotate your canvas back into portrait mode before you draw, and it should all be good. :-)

George Freeman
  • 2,260
  • 1
  • 15
  • 22
  • Yea, when I rotate the emulator it is automatically shifting into landscape mode, but in the real devices, I test it in Sony Ericsson Xperia X10, HTC Legend, HTC Desire S, it is not automatically shifting into landscape mode. I have a question. Does landscape mode work only on emulator ? – George May 10 '11 at 15:47
  • 2
    I think if u will use Tablet than u can see orientation change in live wallpaper too.... @George – MGDroid Mar 13 '14 at 09:01