title: Set Wallpaper from Image Url
body: <p>It's been days now, trying to figure how this function works...
  I have searched for it in stack overflow too ofcourse, 
  <a href="https://stackoverflow.com/questions/20174429/downloading-and-setting-a-wallpaper">Downloading and setting a wallpaper</a>
  tried that, but got doInBackground error.
  and many more "seems legit" answer that I have tried. but in the end, I still had no clue how to change my</p>
  
  <pre><code>  final String url2 = "http://icons.iconarchive.com/icons/3xhumed/mega-games-pack-26/256/Call-of-Duty-World-at-War-5-icon.png";
  
                  displaynya.setImageUrl(url2);
  </code></pre>
  
  <p>to be used when i call it in my button</p>
  
  <pre><code> case R.id.BTsetWalp:
                                          WallpaperManager myWallpaperManager
                                          = WallpaperManager.getInstance(getApplicationContext());
              try {
  
                                  myWallpaperManager.setResource(// what should i do with this?);
  </code></pre>
  
  <p>So confusing..
  the past days, I'm trying to use only an image that has been stored in the apps, using that case 2</p>
  
  <pre><code>case R.id.ivwall02:
                  displaynya.setImageResource(R.drawable.a2);
  
                  setWallp = R.drawable.a2;
                  break;
  </code></pre>
  
  <p>This code is working. but if I use that, my app's size will get huge, because all huge image for wallpaper is stored in the apps. so i want to use a method in case 1 (downloading the image first, then set it to wallpaper), but I'm stuck in there..</p>
  
  <p>==================================================</p>
  
  <p>EDIT 2, updated my code so far</p>
  
  <p>Here is the full code</p>
  
  <pre><code>public class CopyOfGallery extends Activity implements View.OnClickListener {
  private SmartImageView displaynya;
  
  Button bWalp;
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  setContentView(R.layout.gallery);
  
  
      bWalp = (Button) findViewById(R.id.BTsetWalp);
  
      displaynya = (SmartImageView)findViewById(R.id.iVDisplay);
  
  
      ImageView image01 = (ImageView) findViewById(R.id.ivwall01);
      ImageView image02 = (ImageView) findViewById(R.id.ivwall02);
  
  
      image01.setOnClickListener(this);
      image02.setOnClickListener(this);
  
  
      bWalp.setOnClickListener(this);
  
  
          }
  
              @Override
              public void onClick(View vImage) {
                  // TODO Auto-generated method stub
  
                  switch (vImage.getId()){
  
                  case R.id.ivwall01:
  
                      final String url1 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_happy.jpg" ;
                 displaynya.setImageUrl(url1);
  
  
  
  
                      break;
                  case R.id.ivwall02:
  
                      final String url2 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_awkward.jpg" ;
  
                      displaynya.setImageUrl(url2);
  
  
                      break;
  
  
  
                  case R.id.BTsetWalp:
  
  
                          // get the Image to as Bitmap 
                              Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));
  
                                  DisplayMetrics metrics = new DisplayMetrics(); 
                                  getWindowManager().getDefaultDisplay().getMetrics(metrics);
                                  // get the height and width of screen 
                                  int height = metrics.heightPixels; 
                                  int width = metrics.widthPixels;
  
                               WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); 
                  try {
  
                      wallpaperManager.setBitmap(bitmap);
  
                        wallpaperManager.suggestDesiredDimensions(width, height);
  
                  } catch (IOException e) {
                   // TODO Auto-generated catch block
                                      e.printStackTrace();
                  }
  
  
  
                              }}
  </code></pre>
  
  <p>as for</p>
  
  <pre><code>Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));
  </code></pre>
  
  <p>this function is for fetch whatever image that shown in my R.id.iVDisplay isn't?? exactly what i needed. but why it got crash? :'(</p>
  
  <p>here's my log</p>
  
  <blockquote>
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803): FATAL EXCEPTION: main</p>
    
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803):
    java.lang.NullPointerException</p>
    
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803):  at
    android.content.res.Resources.openRawResource(Resources.java:951)</p>
    
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803):  at
    android.content.res.Resources.openRawResource(Resources.java:927)</p>
    
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803):  at
    preff.Gallery.onClick(Gallery.java:355) 01-08 23:39:51.529:
    E/AndroidRuntime(22803):  at
    android.view.View.performClick(View.java:3526)</p>
    
    <p>01-08 23:39:51.529: E/AndroidRuntime(22803):  at
    android.view.View$PerformClick.run(View.java:14133)</p>
  </blockquote>
  
  <p>missplacement or do i missing something? :(</p>