Domanda

I have found plenty of details on how to set a wallpaper from a drawable etc however is it possible to do this from a file location.

I have confirmed that the following code prints out the location of the file

Toast.makeText(MyWallpapers.this, "" + listFile[position].getAbsolutePath(), Toast.LENGTH_SHORT).show();

String ImageLocation = listFile[position].getAbsolutePath();

And so I have been trying something like this to get it to set the wallpaper.

WallpaperManager myWallpaperManager 
        = WallpaperManager.getInstance(getApplicationContext());
try {
    myWallpaperManager.setResource(ImageLocation);
} catch (IOException e) {
    e.printStackTrace();
}

But it doesn't like it.

Any advice?

È stato utile?

Soluzione

Load the file into a Bitmap using BitmapFactory and call WallpaperManager.setBitmap

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top