2012-10-12 69 views
0

我有多個圖像,如果我使用WallpaperManager那麼它將設置壁紙,它被認爲是設置壁紙爲。我如何能夠使用電話和WallpaperManager?使用WallpaperManager和電話

的Java文件(如果需要):

package hd.wallpaper.abs; 

import java.io.IOException; 

import android.app.Activity; 
import android.app.WallpaperManager; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 

public class Main extends Activity implements View.OnClickListener { 

    ImageView display; 
    int toPhone; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_hd__wallpapers); 
     toPhone = R.drawable.eye; 

     display = (ImageView) findViewById(R.id.IVdisplay); 
     ImageView image1 = (ImageView) findViewById(R.id.IVimage1); 
     ImageView image2 = (ImageView) findViewById(R.id.IVimage2); 
     ImageView image3 = (ImageView) findViewById(R.id.IVimage3); 
     ImageView image4 = (ImageView) findViewById(R.id.IVimage4); 
     ImageView image5 = (ImageView) findViewById(R.id.IVimage5); 
     ImageView image6 = (ImageView) findViewById(R.id.IVimage7); 
     Button setWall = (Button) findViewById(R.id.setwallpaperbutton); 
     image1.setOnClickListener(this); 
     image2.setOnClickListener(this); 
     image3.setOnClickListener(this); 
     image4.setOnClickListener(this); 
     image5.setOnClickListener(this); 
     image6.setOnClickListener(this); 
     setWall.setOnClickListener(this); 
    } 

    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     switch (v.getId()) { 
     case R.id.IVimage1: 
     display.setImageResource(R.drawable.i1); 
     toPhone = R.drawable.i1; 
     break; 
     case R.id.IVimage2: 
     display.setImageResource(R.drawable.i2); 
     toPhone = R.drawable.i2; 
     break; 
     case R.id.IVimage3: 
      display.setImageResource(R.drawable.i3); 
      toPhone =R.drawable.i3; 
      break; 
     case R.id.IVimage4: 
      display.setImageResource(R.drawable.i3); 
      toPhone =R.drawable.i3; 
      break; 
     case R.id.IVimage5: 
      display.setImageResource(R.drawable.i3); 
      toPhone =R.drawable.i3; 
      break; 
     case R.id.IVimage7: 
      display.setImageResource(R.drawable.i3); 
      toPhone =R.drawable.solar; 
      break; 
     case R.id.setwallpaperbutton: 
      final WallpaperManager myWallpaperManager 
      = WallpaperManager.getInstance(getApplicationContext()); 
      final int fullWidth = myWallpaperManager.getDesiredMinimumWidth(); 
      final int fullHeight = myWallpaperManager.getDesiredMinimumHeight(); 
      try { 
      myWallpaperManager.setResource(R.drawable.i1); 
      } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
      } 
      break; 

     } 

    } 
    } 
+0

也許[this](http://stackoverflow.com/a/11953435/940096)會給出一些想法。看看那個。 – Praveenkumar

+0

我在發佈之前查看了此內容。正如你在我的Java中看到的,我確實有正確的代碼,並且仍然存在應用程序的問題。 – user1695999

回答

0
case R.id.BsetWallpaper: 
      InputStream first = getResources().openRawResource(toPhone); 
     Bitmap close= BitmapFactory.decodeStream(first);  
     try{ 
      getApplicationContext().setWallpaper(close); 
     }catch (IOException e){ 
      e.printStackTrace(); 
     } 

希望幫助ü!

0
在你的代碼

final WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext()); 
final int fullWidth = myWallpaperManager.getDesiredMinimumWidth(); 
final int fullHeight = myWallpaperManager.getDesiredMinimumHeight(); 
try { 
myWallpaperManager.setResource(R.drawable.i1); 
每次

要設置R.drawable.i1壁紙只是toPhone改變這一點,它應該解決您的問題。