Launcher: Set wallpaper _ intentchooser

Source: Internet
Author: User

Blog Android opensource: launcher study _ set wallpaper _ 01 roughly analyzes the call relationship between the code of the launcher wallpaper.

But for myself, I still feel a little lacking. Today I will make up and continue the study of launcher wallpapers.


I really hope that csdn will allow others to add and edit their blogs, so that we can study the technology more deeply and more precisely, facilitating communication and learning. Hope to be realized one day.


Before talking about the theme, I want to share with you a topic: Is there a future for learning android? What exactly do you want to learn?


When I first started to get started with Android, I didn't even think about the future of learning this thing, so I was dumbly building the environment, downloading development tools, and learning about the basic knowledge of Android. To be honest, I have never touched Java, but I know that Java is a high-level language. Then a friend told me that you cannot learn Java without learning C ++. At that time, I was blinded, how can this problem be solved? I did not believe it myself. I learned it directly.
Java. When I learned about Java, I went back and learned C ++ (I have learned and used C before). Of course, I just understood it!


In addition to reading books and surfing the Internet, I spent the rest of my time writing code. During the last interview, a buddy asked me to write too much upstream code so far? Poor girl, I don't know how to answer the question. I asked him in turn, and the boy smiled! Not many people calculate how many lines of code have been written, especially in this busy age. Others (99% of interviewers) are most concerned about how many projects you have done and what you do in projects? Android is a platform that uses a lot of knowledge. Of course, it depends on which aspect you are interested in? For example, for underlying driver development, you will
C and Linux can be done, and there is no need to learn Java, so I still get a higher salary. The application layer uses network programming, XML parsing, and data storage. Therefore, you must be familiar with the Platform sdk api and have a good Java Foundation! Many companies have high requirements on the UI. If you like Interface Design (a friend of mine is now working on Android UI, It is very strong !) In addition, your salary will be satisfactory if you are doing a very high job. In short, learning Android is not just about itself, it is related to all aspects of technology. Therefore, learning android will not affect your technology. If you are a technology enthusiast, learning android will still have a bright future.


To learn about Android, apart from the knowledge and characteristics of the platform, you must learn Java and learn it well before you can make breakthroughs in the app field. If you want to learn about game development, you still need to learn about data structures and algorithms.


So far, you are welcome to make a brick, exchange, and study.


========================================================== ==========================================================

Next, let's start with the main question. There are two main questions.


1. Intent. createchooser

In launcher. Java, we can see the following code (belonging to the startwallpaper () method)

 private void startWallpaper() {        closeAllApps(true);        final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);        Intent chooser = Intent.createChooser(pickWallpaper,                getText(R.string.chooser_wallpaper));        // NOTE: Adds a configure option to the chooser if the wallpaper supports it        //       Removed in Eclair MR1//        WallpaperManager wm = (WallpaperManager)//                getSystemService(Context.WALLPAPER_SERVICE);//        WallpaperInfo wi = wm.getWallpaperInfo();//        if (wi != null && wi.getSettingsActivity() != null) {//            LabeledIntent li = new LabeledIntent(getPackageName(),//                    R.string.configure_wallpaper, 0);//            li.setClassName(wi.getPackageName(), wi.getSettingsActivity());//            chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });//        }        startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);    }

When executing this code, the system will call the relevant activity to respond to the event. To better understand it, let's try a demo.

A. Create a project intentcreatechooserdemo

Very simple: An activity. click the button to trigger the event. The source code is as follows:

Package mark. zhang. main; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onclicklistener; public class intentcreatchooserdemoactivity extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); findviewbyid (R. id. btn_click ). setonclicklistener (New onclicklistener () {@ override public void onclick (view v) {final intent mintent = new intent ("mark. zhang. intent "); intent chooser = intent. createchooser (mintent, "list"); startactivity (chooser );}});}}

B. Create a project responseactivity, which contains only two


The project structure is as follows:



The two activity code sections are simple, with the same code and layout:

package mark.zhang.response;import android.app.Activity;import android.os.Bundle;public class ResponseActivity extends Activity {        @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }}

Let's take a look at the manifest. xml file:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="mark.zhang.response"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="10" />    <application        android:icon="@drawable/ic_launcher"        android:label="ResActivityI" >        <activity          android:label="ResActivityI"            android:name=".ResponseActivity" >            <intent-filter >                <action android:name="mark.zhang.intent" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        </activity>                     <activity                  android:label="ResActivityII"            android:name=".ResActivityII" >            <intent-filter >                <action android:name="mark.zhang.intent" />                <category android:name="android.intent.category.DEFAULT" />            </intent-filter>        </activity>    </application></manifest>

It is very simple. It is an activity. click the button to trigger the event. The source code is as follows. zhang. intent, and then the category is Android. intent. category. default. Note that if you implicitly start an activity, the category option must be included. Otherwise, the activity cannot be found only by action.

C. Run


Run the responseactivity project first and then intentcreatechooserdemo. The effect is as follows:




So far, you can understand that even if these two activities are not in the same app as the activity to be started, it is also effective. Of course, if these two activities are in the same app as the activity to be started
Yes, you can verify it on your own.


2. Change the launcher background


The XML file that laucher loads for the first time is launcher. XML, which is located under Res/Layout-land.

I want to change the background in the launcher. XM l file of launcher, that is, add the background attribute, but the effect is quite different. After the change, I want to add another wallpaper for the launcher, or the dynamic wallpaper will not work.


Therefore, you should pay attention to this point during the development process.



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.