I'm trying to create an app which allows users to screenshot the current view. I'm using the following code to do so.
View content = ((Activity)ctx).findViewById(R.id.rootlayout);
Bitmap bitmap = content.getDrawingCache();
File file = new File("/sdcard/test.png");
try
{
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
However, i'm getting a Null Pointer Exception on the following line:
Bitmap bitmap = content.getDrawingCache();
What would this mean, that the view is empty?
Any help would be great!