2012-03-27 74 views

回答

1

首先在AndroidManifest.xml文件中添加此權限

<uses-permission android:name="android.permission.SET_WALLPAPER"> 

的main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 

    android:orientation="vertical" > 

    <Button 
     android:layout_margin="20dp" 
     android:id="@+id/set" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Set WallPaper" /> 
<ImageView 
     android:layout_margin="20dp" 
     android:id="@+id/preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     /> 

</LinearLayout> 

然後下面是Java代碼,你要實現哪些:

 public class SetWallpaper extends Activity { 
      Bitmap bitmap; 
      int lastImageRef; 

      /** Called when the activity is first created. */ 
      @Override 
      public void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 
       setContentView(R.layout.main); 

       Button buttonSetWallpaper = (Button)findViewById(R.id.set); 
       ImageView imagePreview = (ImageView)findViewById(R.id.ic_launcher); 
       imagePreview.setImageResource(R.drawable.five); 

       buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){ 
        @Override 
        public void onClick(View arg0) { 
         // TODO Auto-generated method stub 
         WallpaperManager myWallpaperManager 
         = WallpaperManager.getInstance(getApplicationContext()); 
         try { 
           myWallpaperManager.setResource(R.drawable.ic_launcher); 
         } catch (IOException e) { 
           // TODO Auto-generated catch block 
           e.printStackTrace(); 
         } 
        }}); 
      } 
     } 
0

是的你indeed can

public void setStream (InputStream data) 

developers site

改變當前系統壁紙到一個特定的字節流。給InputStream 複製到持久存儲中,現在將作爲壁紙使用 。目前它必須是JPEG或PNG 圖片。成功時,廣播意圖ACTION_WALLPAPER_CHANGED。 參數

data包含要作爲壁紙安裝的原始數據的流。