I have this code which is meant to take screenshots. I had it up and running perfectly fine in one of my apps which I was using as a “rough draft”.
However, now that I copied the code into my original project, it seems like the code never really enters the “try” portion. This is kind of confusing since it is still running fine on the other sample app but not here. And just for your information, no errors are being posted either. What is happening here?
public void getScreen()
{
View table = findViewById(R.id.TransactionLog);
table.setDrawingCacheEnabled(true);
table.buildDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(table.getDrawingCache());
table.setDrawingCacheEnabled(false); // Clear drawing cache
File doc = new File( Environment.getExternalStorageDirectory() + "TransactionHistory.png");
try
{
doc.createNewFile();
FileOutputStream ostream = new FileOutputStream(doc);
bitmap.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
sendmail();
}
catch (Exception e)
{
e.printStackTrace();
}
}
As well as all the other suggestions made, it could be throwing an exception on the line:
in which case it will never enter your try/catch. Put some logging statements or debugging breakpoints at the beginning of the method and anywhere the method is being called.