0
  1. Shows s JPEG image.
  2. Display a button over the image that allows the user to set the image to their wallpaper.
  3. Auto resizes the image to the users specific Android phone display size.
  4. Removes the wallpaper if the app is uninstalled.

I can do step 1 and 2 pretty easy i'm just stuck with the other two steps can anyone point me in the right direction. here is the code so far

public class MainActivity extends Activity implements OnClickListener {

    ImageView iv;
    Button b;
    Intent i;
    Bitmap bmp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initialize();
        InputStream is = getResources().openRawResource(R.drawable.image);
        bmp = BitmapFactory.decodeStream(is);
    }
    private void initialize(){
        iv = (ImageView) findViewById(R.id.ivReturnedPic);
        b = (Button) findViewById(R.id.bSetWallpaper);
        b.setOnClickListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.bSetWallpaper:
            try {
                getApplicationContext().setWallpaper(bmp);
            } catch (IOException e) {

                e.printStackTrace();
            }
            break;
        }
    }

}
jnthnjns
  • 8,962
  • 4
  • 42
  • 65
  • What is your problem? – Pragnani Apr 09 '13 at 16:54
  • 1
    `Removes the wallpaper if the app is uninstalled.` this one is not possible, your app doesn't get a callback when it is uninstalled and thus you cannot execute any code at that time. – FoamyGuy Apr 09 '13 at 17:09

1 Answers1

0

to set the wallpaper on the desired screen size

WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplication());
int height = myWallpaperManager.getDesiredMinimumHeight();
int width = myWallpaperManager.getDesiredMinimumWidth();

try {
    myWallpaperManager.setBitmap(Bitmap.createScaledBitmap(setAs, width , height , true));   
} catch (final IOException e) {
    Toast.makeText(getApplication(), "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}

and for the fourth question please refer to this

Community
  • 1
  • 1
Kosh
  • 6,140
  • 3
  • 36
  • 67