Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6756123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:29:13+00:00 2026-05-26T13:29:13+00:00

I have this code to take screenshots of layouts in Android. It is not

  • 0

I have this code to take screenshots of layouts in Android. It is not throwing any errors, however, the screenshot is not being taken either. Can someone please help me figure out what I am doing wrong here? I am new with Eclipse and I am having a hard time figuring things out. Also if there is any other way to take screenshots can you post it as an answer to this thread? Thanks for your time!

  private void getScreenshot()
                {
                    View content = findViewById(R.id.testView);
                    content.setDrawingCacheEnabled(true);

                    content.buildDrawingCache(true);

                    Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache());
                    content.setDrawingCacheEnabled(false);

                    File file = new File( Environment.getExternalStorageDirectory() + "image.png");

                    try 
                    {
                        file.createNewFile();
                        FileOutputStream ostream = new FileOutputStream(file);
                        bitmap.compress(CompressFormat.PNG, 100, ostream);
                        ostream.close();

                    } 
                    catch (Exception e) 
                    {
                        e.printStackTrace();
                    }

                    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:29:13+00:00Added an answer on May 26, 2026 at 1:29 pm

    Do you need to add path separator into your File? i.e.

    File file = new File(Environment.getExternalStorageDirectory() + 
                         File.separator + "image.png");
    

    You should add a lot more logs and tests in your code to check whether it is behaving as you would expect, e.g.

    • Log the details of the file you are trying to create to be sure it is correct.

    • Once you’ve created the file, test that it exists, e.g. if (!file.exists())

    • The Bitmap.compress function returns a boolean, so you should check the return value and log it to see if it succeeded.

    One other thought: maybe you need to call ostream.flush() (API docs here) to ensure the buffered data is written to the file?

    I’m assuming you’re writing this code for use within your app. You probably already know this, but DDMS provides a way to take screenshots in case you just want to take some yourself. Just make sure to select the device to enable the Screenshot menu option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which is meant to take screenshots. I had it up
I have this code for taking a screenshot; how could I change it to
I have this code: startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), CAMERA_IMAGE); That allows that user to take a
So I have this code. Basically it should be able to take a stock
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.