Livewallpaper, a dynamic wallpaper, is a 3D feature of Android. Users can choose to attach dynamic wallpaper on the desktop to rotate the desktop background of their mobile phones.
Compared with static desktop wallpapers, dynamic wallpapers can display a variety of dynamic backgrounds. Unlike traditional mobile phone systems that use GIF as a dynamic background, Android dynamic wallpapers are not GIF images, it is a standard Android application, that is, APK. Since it is an application, of course, it means that it is born with a function not available in GIF images-it can interact with users, moreover, dynamic background changes are not limited to the loop playback of fixed images as GIF images.
It should be noted that the standard Android system can set dynamic GIF images as wallpaper, but it cannot dynamically run GIF images. That is to say, if you use GIF images as wallpaper, you can only see one static image. You cannot see the dynamic effect of GIF images on the desktop as on many other system hosts. This limitation is a major defect of Android, which is related to the design defect of the android wallpaper framework. Of course, since you can load a variety of types of mobile Android dynamic wallpapers with interactive effects, a little pity about GIF images is acceptable.
Android built-in dynamic wallpaper is implemented based on renderscript. renderscript is a type of C language that Google uses for Android. Its structure is similar to that of C, it encapsulates the standard API of OpenGL and can load the renderscript file to run it at runtime. That is to say, if you want to develop a new dynamic wallpaper Based on renderscript, you should have a certain understanding of common OpenGL APIs. In addition, Google's current development materials for renderscript are not perfect, and the renderscript has not been inherited into ADT in the public release SDK. In other words, if you want to use renderscript to develop new dynamic wallpapers, you cannot develop in eclipse Based on ADT or SDK. Instead, you should download the complete source code and compile the entire framework, and then write new applications in your own Linux compiling environment. Because renderscript calls the OpenGL interface, your developed application must be able to run on a real machine, and your machine must support 3D, that is, OpenGL. If you find that some manufacturers' mobile phone desktops do not have a portal to load dynamic wallpaper, you do not need to say that the mobile phone does not support 3D at all, this is important for those who want to buy a real machine to learn how to develop andoid.
Google has built a certain number of dynamic wallpapers in each Android version released. The dynamic Wallpaper Code of each version is slightly different, however, the name, effect, and number of dynamic wallpapers are basically the same. Next, let's take a look at the location of the dynamic wallpaper code. We open Google Android Source Code address: http://android.git.kernel.org/
As you can see, the built-in dynamic wallpaper of Android is in the packages/wallpapers/directory, and the GIT clone method is used (see the blog post "Download Android source code -- download a single directory by using git clone ", http://blog.csdn.net/droidpioneer/article/details/6612026) quickly download each sub-directory Android version of the android built-in dynamic wallpaper code. Among them, the basic and musicvisualization directories contain multiple dynamic wallpapers with the same code framework. The magicsmoke directory only contains one dynamic wallpaper of magic smoke, the livepicker directory contains the code of the dynamic wallpaper selection list, that is, the implementation code of the list of all dynamic wallpapers in the system that appears when you choose to add dynamic wallpaper on the desktop.
So what is the essence of dynamic wallpaper? As mentioned above, it is an APK, but it is a special APK. Open the androidmanifest. xml file of magicsomke:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.magicsmoke"> <original-package android:name="com.android.magicsmoke" /> <uses-feature android:name="android.software.live_wallpaper" /> <uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" /> <uses-permission android:name="android.permission.BIND_WALLPAPER" /> <application android:label="@string/wallpapers" android:icon="@drawable/ic_launcher_wallpaper"> <service android:label="@string/wallpaper_magicsmoke" android:name="MagicSmoke" 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/magicsmoke" /> </service> <activity android:name="com.android.magicsmoke.MagicSmokeSelector" android:theme="@style/Preview" android:exported="true"> </activity> </application></manifest>
I have already guessed that the android dynamic wallpaper is essentially a "service", which can be loaded by the launcher on the main interface. So how can launcher identify this APK with dynamic wallpaper service? The intent-filter action of the above androidmanifest. xml file leaks the following:
<action android:name="android.service.wallpaper.WallpaperService" />
Yes. The system officially uses the APK action to load it into the livepicker list as a dynamic wallpaper. You can select your favorite dynamic wallpaper in the livepicker list, then, the dynamic wallpaper is displayed behind the launcher.
It should be noted that although the android dynamic wallpaper seems to be displayed in the launcher background, it is only an illusion that the dynamic wallpaper and launcher are completely different processes, however, the launcher and the dynamic wallpaper process can communicate with each other through the wallpapermanager in the framework. When a user slides the launcher desktop and clicks the screen, some dynamic wallpapers can interact with each other, in fact, this process completes communication. If you use the code to set the background of the launcher to non-transparent, such as using an opaque image or color as the background, then you will not see any dynamic wallpaper effect. Of course, in this case, you won't see the static wallpaper either.