문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top