Android setWallpaper deprecated -


i want create application allows me set phone's wallpaper, have problem : getapplicationcontext().setwallpaper(bm).
says setwallpaper deprecated , should use method, have no idea method use.
code far:

   package com.example.asus.incercare_proiect;  /**  * created asus on 29-apr-15.  */ import java.io.ioexception; import java.io.inputstream; import android.app.activity; import android.graphics.bitmap; import android.graphics.bitmapfactory; import android.os.bundle; import android.view.view; import android.view.window; import android.view.windowmanager; import android.view.view.onclicklistener; import android.widget.button; import android.widget.imageview; import android.widget.toast;   class bakapp extends activity implements onclicklistener {     imageview display;     int tophone;      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);          // activitatea noastra sa acopere intreg ecranul         requestwindowfeature(window.feature_no_title);         getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,                 windowmanager.layoutparams.flag_fullscreen);          setcontentview(r.layout.backapp);         button = (button) findviewbyid(r.id.setwallpaper);         tophone = r.drawable.image4;         but.setonclicklistener(this);         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.image4);         imageview image5 = (imageview) findviewbyid(r.id.ivimage5);          image1.setonclicklistener(this);         image2.setonclicklistener(this);         image3.setonclicklistener(this);         image4.setonclicklistener(this);         image5.setonclicklistener(this);      }      @override     public void onclick(view v) {         // todo auto-generated method stub         toast var;         switch (v.getid()) {             case r.id.ivimage1:                 display.setimageresource(r.drawable.image4);                 var = toast.maketext(bakapp.this, "image changed",                         toast.length_short);                  var.show();                  tophone = r.drawable.image4;                 break;             case r.id.ivimage2:                 display.setimageresource(r.drawable.image5);                 var = toast.maketext(bakapp.this, "image changed",                         toast.length_short);                  var.show();                  tophone = r.drawable.image5;                 break;             case r.id.ivimage3:                 display.setimageresource(r.drawable.image6);                 var = toast.maketext(bakapp.this, "image changed",                         toast.length_short);                  var.show();                  tophone = r.drawable.image6;                 break;             case r.id.image4:                 display.setimageresource(r.drawable.image7);                 var = toast.maketext(bakapp.this, "image changed",                         toast.length_short);                  var.show();                  tophone = r.drawable.image7;                 break;             case r.id.ivimage5:                 display.setimageresource(r.drawable.image8);                 var = toast.maketext(bakapp.this, "image changed",                         toast.length_short);                  var.show();                  tophone = r.drawable.image8;                 break;             case r.id.setwallpaper:                 // trebuie folosit bitmap                 inputstream = getresources().openrawresource(tophone);                  bitmap bm = bitmapfactory.decodestream(is);                  try {                     getapplicationcontext().setwallpaper(bm);                  // trebuie sa cerem permisiune pentru seta wallpaperul                  } catch (ioexception e) {                     // todo auto-generated catch block                     e.printstacktrace();                 }            var = toast.maketext(bakapp.this, "wallpaper image changed",                         toast.length_short);                  var.show();                  break;         }     }  } 

could me out?

if take @ official docs, find, method deprecated since api 5 , should use wallpapermanager.setbitmap() instead.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -