Android principle Secret Series One of the dynamic wallpaper

Source: Internet
Author: User

Livewallpaper, the dynamic wallpaper, is a big 3D feature of Android, the user can choose to load the dynamic wallpaper on the desktop, let their mobile desktop background spin up.

Compared to static desktop wallpaper, dynamic wallpaper can show a variety of dynamic background, and unlike the traditional mobile system using GIF as a dynamic background, Android's dynamic wallpaper is not a GIF image, but a standard Android app, that is, apk. Since it is an application, of course, it means that there is a natural feature that GIF images do not have-the ability to interact with the user, and that the dynamic background changes are not limited to GIF images, but only a few loops of a fixed number of pictures.

It should be noted that the standard Android system can support animated GIF images as wallpaper, but does not dynamically run GIF images. In other words, if you use a GIF as a wallpaper, you can only see a static picture, not as many other system's Shanzhai machine can see the GIF picture animated effect on the desktop. This limitation is a major flaw in Android, and this flaw is related to the design flaws of the Android wallpaper framework. Of course, since you can load a rich type of spinning interactive Android wallpaper, then a little regret for GIF pictures is perfectly acceptable.

Android built-in dynamic wallpaper is based on renderscript implementation, Renderscript is Google for Android, a Class C language, and the C language structure is very similar to the standard OpenGL API is packaged in a simple, You can then load the Renderscript file at run time to run. In other words, if you want to develop new dynamic wallpaper based on renderscript, you should have a certain understanding of OpenGL's Common API. In addition, Google's current development of Renderscript is not very perfect, in the public release of the SDK also temporarily did not put Renderscript into ADT, in other words, if you want to use Renderscript to develop new dynamic wallpaper, You can't develop under eclipse based on the ADT and SDK, instead download the full source and compile the entire framework, and then write the new app in your Linux build environment. Because Renderscript is going to invoke the OpenGL interface, the app you're developing should be able to run on the real machine, and you have to support the page, which is OpenGL. If you find that some manufacturers of mobile phone desktop does not load the portal of dynamic wallpaper, then needless to say, that must be the phone does not support the andoid, this point for the purchase of real machine to learn the development of the friends must be careful.

Google in the release of the various Android version has built up a certain number of dynamic wallpaper, each version of the dynamic wallpaper code a little difference, but the dynamic wallpaper name, visual effect, the number is basically the same. Let's look at where the code for these dynamic wallpapers is located. We open Google's Android source code address: http://android.git.kernel.org/

As you can see, the Android built-in dynamic wallpaper is in the packages/wallpapers/directory, through the Git clone method (see "Android source download-with Git clone for a single directory Download", http:// www.linuxidc.com/Linux/2011-07/38953.htm) quickly download various subdirectories for each Android version of Android built-in dynamic wallpaper code. The Basic, musicvisualization two directories contain multiple dynamic wallpaper of the same code framework, the Magicsmoke directory contains only magical smoke a dynamic wallpaper, Livepicker directory contains the dynamic wallpaper selection list of code, This is the implementation code for the list of all the dynamic wallpaper in the system that appears when you select Add Dynamic wallpaper on the desktop.

So, what is the nature of dynamic wallpaper? As I mentioned earlier, it's apk, but it's a very special apk. We might as well open the Magicsomke androidmanifest.xml file:

<SpanStyle= "FONT-SIZE:16PX;"><ManifestXmlns:android= "Http://schemas.android.com/apk/res/android"Package= "com. Android.magicsmoke "><Original-packageAndroid:name= "Com.android.magicsmoke"/><Uses-featureAndroid:name= "Android.software.live_wallpaper"/><Uses-permissionAndroid:name= "Android.permission.SET_WALLPAPER_COMPONENT"/><Uses-permissionAndroid:name= "Android.permission.BIND_WALLPAPER"/><ApplicationAndroid:label= "@string/wallpapers"Android:icon= "@drawable/ic_launcher_wallpaper"><ServiceAndroid:label= "@string/wallpaper_magicsmoke"Android:name= "Magicsmoke"Android:permission= "Android.permission.BIND_WALLPAPER"><Intent-filter><ActionAndroid:name= "Android.service.wallpaper.WallpaperService"/></Intent-filter><Meta-dataAndroid:name="Android.service.wallpaper"android:resource= "@xml/magicsmoke" /> </service> < activity android:name= " Com.android.magicsmoke.MagicSmokeSelector "android:theme=" @style/preview " android:exported= "true" > </< span class= "HTML" >activity> </application> </manifest>  </span>          

I think the careful friend has guessed, the nature of the Android dynamic wallpaper is a "service", the service can be loaded by the main interface launcher. So how can launcher identify the apk that contains the dynamic wallpaper service? The Intent-filter action of the Androidmanifest.xml file above leaks the secret:

<android:name/> 

Yes, the system officially through the APK action as a dynamic wallpaper loaded into the Livepicker list, the user in the Livepicker table select their favorite dynamic wallpaper, and then display the dynamic wallpaper into the launcher behind.

It should be noted that, although the Android dynamic wallpaper appears to be displayed in the background of launcher, but in fact this is only a false impression, dynamic wallpaper and launcher are completely different two processes, but launcher and dynamic The process of wallpaper can be wallpapermanager through the framework of inter-process communication, users in the Launcher desktop sliding, click on the screen when the dynamic wallpaper can produce interactive effect, is actually the process of communication completed. If you use the code to set the background of a launcher to be opaque, such as an opaque image or a color background, you will not see any dynamic wallpaper effect, and of course, you will not see the static wallpaper.

Android principle Secret Series One of the dynamic wallpaper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.