I have to design an app in which on click of the neutral button, an image of the alert dialogue gets stored in the sdcard. So I decided to programatically take a screenshot and then use the BitmapDecodeRegion class to crop the image.
But when i take the screenshot, the alert dialogue does not appear in it since it's not attached to the window. How can I attach it to the window?
here is the code snippet:
public void btnClick(View v) {
Log.d("", "logger button clicked");
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle("This is a demo!");
dialog.setMessage("Lets see if this works");
dialog.setCancelable(false);
dialog.setNeutralButton("Take Snap",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bitmap bitmap;
View v1 = findViewById(android.R.id.content)
.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
GlobalObj.screenImg = bitmap;
v1.setDrawingCacheEnabled(false);
Intent i = new Intent(MainActivity.this,
ViewActivity.class);
startActivity(i);
}
});
AlertDialog newDialog = dialog.create();
newDialog.show();
Kindly help me out.