Search code examples
androidexceptionwallpaper

set wallpaper should be this hard :(


ok i think it's throwing an exception. unfortunately i am not getting an error. it loads on the emulator and my phone but won't perform. it just says, "The application MyApp (process com.myapp) has stopped unexpectedly. Please try again." and then a ForceClose button. :(

once again here is my code:

public void onClick(DialogInterface dialog, int id) {
    try {
        MyActivity.this.setWallpaper(mContext.getDrawingCache()); 
        finish();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

on my own research i saw someone getting the bit map from getDrawingCache and converting it to a bitmap? but the documentation on view.getDrawingCache says it is already a bitmap, and setWallpaper is supposed to set a bitmap... i am out of ideas here.


Solution

  • What is mContext? getDrawingCache() is a method of the View class, and will only return a valid Bitmap if you first call setDrawingCacheEnabled(true) or if you call buildDrawingCache(). You also must make sure that the View went through a layout pass and that its width and height are > 0.