Setting wallpaper in Android

前端 未结 3 1865
离开以前
离开以前 2021-01-01 03:25

I am developing a simple app that sets wallpapers based on user input. I am missing code for setting wallpapers. I have been looking for it in lots of websites in vain. Can

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 03:53

    u can try

    InputStream inputStream = getResources().openRawResource(wallpaperResource);
    Bitmap setWallToDevice = BitmapFactory.decodeStream(inputStream);
    
    try {
    getApplicationContext().setWallpaper(setWallToDevice);
    } catch (IOException e) {
    // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    however this method is deprecated so u can use

    try {
    WallpaperManager.getInstance(getApplicationContext()).setResource(wallpaperResource);
    } catch (IOException e){
    e.printStackTrace();
    }
    

提交回复
热议问题