how to take a screen shot on a button click can anyone provide a android code

android screen capture source code
android take screenshot programmatically background
unexpected error while obtaining screenshot from device: eof
android take screenshot programmatically from service
android take screenshot programmatically without root
how to take screenshot of imageview in android
how to take screenshot of particular layout in android studio
android how to capture screen programmatically

I want to take the screen shot of current screen when,I click a button.Can anyone provide a android code.I need to save the image in the gallery also.this is what i tried

public class CaptureScreenShots extends Activity {
LinearLayout L1;
ImageView image;
 @Override
     protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen_shots);
    L1 = (LinearLayout) findViewById(R.id.LinearLayout01);
    Button but = (Button) findViewById(R.id.munchscreen);
    but.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            View v1 = L1.getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bm = v1.getDrawingCache();
            BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
            image = (ImageView) findViewById(R.id.screenshots);
            image.setBackgroundDrawable(bitmapDrawable);
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.screen_shots, menu);
    return true;
}

}
private void getScreen(){
View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.free_tiket)+".jpg");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage( getContentResolver(), b, "Screen", "screen");
} catch (FileNotFoundException e) {
   e.printStackTrace();
} catch (Exception e) {
   e.printStackTrace();

}

Taking a screenshot programmatically in Android Apps, Taking a screenshot programmatically in an Android Application can be very interesting to Duration: 8:30 Posted: Jul 10, 2018 The screen flashes white. Your device captures the entire screen and saves it as a photo. Which one is the Sleep/Wake button? It’s that isolated button which is either at the left (iPad), at the top (e.g. iPod touch) or on the right side (e.g. iPhone 7, 8, X, 11). Where do I find my screenshots?

set button click listener

share = (Button)findViewById(R.id.share);
share.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Bitmap bitmap = takeScreenshot();
        saveBitmap(bitmap);

    }
});

then you have to create two method

public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}

public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
    fos = new FileOutputStream(imagePath);
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
    fos.flush();
    fos.close();
} catch (FileNotFoundException e) {
    Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
    Log.e("GREC", e.getMessage(), e);
}
}

After add this code into your app, run the app and check your local storage, you have created screen shot of whole page.

Taking a screenshot of current Activity in Android – Android , In this post I'll show how you can take a screenshot of your current we want to take the screenshot when a button is clicked, the code will look� You can take a picture of your phone's screen. The image is called a screenshot. After you capture your screen you can view, edit, and share the image. Important: Some of these steps work only on And

I followed your code,when i am click the button image will stored as black screen because i developed with surfaceview custom camera...What will do complete image save in local storage.

Learn to take a Screenshot programmatically on Android, Learn how to take a Screenshot programmatically on Android with this tutorial. Let the Duration: 8:30 Posted: May 15, 2017 From any screen, simply swipe three fingers down the screen on a Xiaomi device and it will grab a shot of the screen. You can also jump into the settings and assign a range of different shortcuts

Take a screenshot, Use the Screen Capture tool to take a screenshot of the display on a hardware device or the emulator. On many Android devices, you can capture a screenshot with a Click Screen Capture on the left side of the window. Content and code samples on this page are subject to the licenses described in� Take a full-screen screenshot. To capture an image of your entire display and save it to a file on the desktop, press ⌘+ ⇧ Shift+3. The computer will make the sound of a camera shutter, and a file labeled "Screen Shot [date]" will appear on your desktop.

Take a screenshot on your Android device, After you capture your screen you can view, edit, and share the image. Press and hold the Power + Volume down buttons at the same time for a few seconds. Click the screenshot button and this tool saves an image to C:Users<user name>Videos>Captures by default. To use this tool, make sure the Game bar’s screen capture feature is toggled on in

How do I take a screen capture on my smartphone?, smartphone? Learn how to take a screenshot on your smartphone in this article . Now that we've got those easy ones out of the way, let's take a look at some phones that make it a lot harder to crack the capture code. There's no simple button pressing for early Android users. Click on it and you'll see "screen capture. PrtScn: Hitting the button once saves a screenshot of the entire screen. If you have multiple monitors connected, a single press of the print screen button will save a screenshot of all the screens in one single image. Alt+PrtScn: Strike these buttons at the same time to take a screenshot of a single window that you're focused on. Select the

Comments
  • I'm voting to close this question as off-topic because "can I haz teh code?" questions are off-topic. Please show us what you have done.
  • similar ques stackoverflow.com/questions/2661536/…
  • public class CaptureScreenShots extends Activity { LinearLayout L1; ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_shots); L1 = (LinearLayout) findViewById(R.id.LinearLayout01); Button but = (Button) findViewById(R.id.munchscreen); but.setOnClickListener(new OnClickListener() {
  • @Override public void onClick(View v) { View v1 = L1.getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bm = v1.getDrawingCache(); BitmapDrawable bitmapDrawable = new BitmapDrawable(bm); image = (ImageView) findViewById(R.id.screenshots); image.setBackgroundDrawable(bitmapDrawable); } }); }
  • i am a beginner,sorry for my mistake @Little Child
  • does it automatically save the photo to our memory
  • No. You have to implement to manually. First create a folder through programatically and then specify path where you want to store your pic.
  • Either you can save path in Any location in you mobile and when you need that image call image path and change image path to Bitmap and apply to imageView
  • This captures the status bar as white
  • simple and concise answer.