Pergunta

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?

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top