private void sendScreenshot() { Bitmap bitmap = mIitcWebView.getDrawingCache(); if (bitmap == null) { mIitcWebView.buildDrawingCache(); bitmap = mIitcWebView.getDrawingCache(); if (bitmap == null) { Log.e("could not get bitmap!"); return; } bitmap = Bitmap.createBitmap(bitmap); if (!mIitcWebView.isDrawingCacheEnabled()) mIitcWebView.destroyDrawingCache(); } else { bitmap = Bitmap.createBitmap(bitmap); } try { final File cache = getExternalCacheDir(); final File file = File.createTempFile("IITC screenshot", ".png", cache); if (!bitmap.compress(CompressFormat.PNG, 100, new FileOutputStream(file))) { // quality is ignored by PNG throw new IOException("Could not compress bitmap!"); } startActivityForResult( ShareActivity.forFile(this, file, "image/png"), new ResponseHandler() { @Override public void onActivityResult(final int resultCode, final Intent data) { file.delete(); } }); } catch (final IOException e) { Log.e("Could not generate screenshot", e); } }
public void startActivityForResult(final Intent launch, final ResponseHandler handler) { int index = mResponseHandlers.indexOf(handler); if (index == -1) { mResponseHandlers.add(handler); index = mResponseHandlers.indexOf(handler); } startActivityForResult(launch, RESULT_FIRST_USER + index); }