views:

1460

answers:

1

What i'm trying to do is, set the wallpaper using an image URI (no cropping)

I'm a noob at dev on Android and dev in general. The internet has failed me... on providing code to set the wallpaper.

yes the dev resource site says

public void setStream (InputStream data)

but i don't understand it, some sample code would greatly help me.

A: 

If you have the image URL you can open the resource it represent using the stream(abstraction): new URL("your.image.url.com").openStream(). This method call will return an object of type InputStream which you can pass as an argument to setStream() method.

If you dont want to specify a stream directly, you can open the remote stream, create a Bitmap and then either use a WallpaperManager instance or do a context.setWallpaper(bitmap)(this is deprecated) to set your bitmap as the wallpaper.

For reference take a look at this thread.

Samuh
This is my current code...InputStream is = getContentResolver().openInputStream(imageUri);bgImage = BitmapFactory.decodeStream(is);Context context = this.getBaseContext();context.setWallpaper(bgImage);`Errors at bgImage (line 2 and 4) and getBaseContext() (line 3)also whats the difference between a URI and a URL?Short answer i got was "A URL is a URI but, a URI is not a URL"
asdf.BEN
ok i fixed the errors on lines 2 and 4, i didn't define the Bitmap bgImage. but still errors on getBaseContext()
asdf.BEN
You know you can pass an instance of Activity as Context right? No need to do a this.getBaseContext() you can pass instance of current activity or a context object if you have one["this" would be a valid context object]
Samuh
And yes there is difference between URI and URL..
Samuh