There are many android applications in Google Play Store which help us to take the screen of android device. As a developer, in this tutorial, I will show how to take a screenshot of your android application programmatically. It is good to take screen shot and share your application to the friends via email, mms etc.

You can easily take screenshot of particular android layout, activity or views and child views. So, here I am going to show how to take a screen shot of whole activity programmatically in android.

Taking screenshot programmatically is not so difficult but you have to know little bit java code. In android, screenshot can be taken with different ways and this is one of the simplest ways.

Taking Screenshot of Android Application in Android Emulator and Real Device from Android Studio
How to Get the IP Address of Android Device Programmatically
How to Get Registered Email Address Programmatically in Android

Android Example: Taking Screenshot Programmatically in Android

Following is the example code of java activity file and XML file.

XML Layout File

Following is the XML layout file where I have added a button, textview and an imageview in a linear layout. And I have also added onClick attribute in the button.

res/layout/ taking_screenshot_in_android.xml

Java Activity File

This is android activity file where I have added some java code to take screenshot and import android.graphics.Bitmap;, java.io.ByteArrayOutputStream;, java.io.File; etc.

src/ TakingScreenShotAndroid.java

Strings.xml File


Android Example: Taking Screenshot Programmatically in Android

That’s all. Now run your How to Take Screenshot Programmatically in Android application and click on Take ScreenShot button, you will see the screenshot of your application below the button.

Post a Comment

Powered by Blogger.