I saw the following link and it takes a screenshot with the top answer
However, I want the application to take a screenshot of the Alert Dialog dialog box, which I show the user, the solution above and the code below only take a screenshot of what is currently behind the warning dialog, and therefore there is no good
Here is the code used if someone didnβt go through the provided link
Date now = new Date(); android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now); try { // image naming and path to include sd card appending name you choose for file String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg"; // create bitmap screen capture View v1 = getWindow().getDecorView().getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); File imageFile = new File(mPath); FileOutputStream outputStream = new FileOutputStream(imageFile); int quality = 100; bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream); outputStream.flush(); outputStream.close(); openScreenshot(imageFile); } catch (Throwable e) { // Several error may come out with file handling or OOM e.printStackTrace(); }
EDIT: code for dialog on request
public void showCalc(String title, String message) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(true); builder.setTitle(title); builder.setMessage(message); builder.setPositiveButton("Capture + Open", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) {
FURTHER EDITION:
Here you will see two screenshots, the first shows the saved screenshot, when everything is saved in the screenshot from the dialog box, you will notice that there is some text below that is always present below.

In the second screenshot there is so much text in the dialog box that the dialogue scrolls so that you can see all the data, you will notice that the bottom line in the first screenshot is missing

If possible, I would like all the data to be displayed, I'm not sure if the screenshot function can do this or an alternative method