How To Take A Screenshot In Android Programmatically
Let the users to take a screenshot in an android application can be useful to let their to share results in a game or.
How to take a screenshot in android programmatically. Our getscreenshot method will generate a bitmap and we can perform actions on it. Don t forget after this call to disable drawing cache on the view v. By default my activity is mainactivity java. Resources string name app name take screenshot demo string string name sharing text your sharing text goes here string string name share title share screenshot string.
Let assume that your activity root layout is linear layout. Taking screen shot in the background like adb requires groups 1003 graphics. Now we must enable drawing cache on view v and access to content thanks to getdrawingcache method. Learn how to take a screenshot programmatically on android with this tutorial.
You can take screenshot of any portion of your view you just need the reference of the layout of which you want the screenshot. Xml version 1 0 encoding utf 8 linearlayout. Step 3 create screenshotutil class. For example in your case you want the screen shot of your activity.
View v getwindow getdecorview getrootview. Android sdk offers in standard the possibility to get a bitmap representation of a specific view. Step 2 update activity main xml. So to take a screenshot of the content displayed to the user on the screen the main idea is to.
Rest of the code consists to write the created bitmap in a dedicated file and then you can use the screenshot contained in the file like you want in your application. Step 1 create a new project in android studio go to file new project and fill all required details to create a new project. Otherwise you can only get the screen shot of your own process. These are some strings that we are going to use in our project.
Android take screenshot programmatically. Getscreenshot your view here view is the layout view which we want to take screenshot. Step 4 create fileutil class. Step 2 add the following code to res layout activity main xml.
Open res values strings xmland add below string values. Resources string name app. Step 1 update strings xml. How to programmatically take a screenshot in android.
Add the below string values to the string xml located in res values strings xml.