Take Screenshot of Android screen and save to SD card

前端 未结 4 621
南旧
南旧 2021-01-16 09:00

There are a few questions here on SO about capturing screenshots of an android application. However, I haven\'t found a solid solution on how to take a screenshot programati

4条回答
  •  渐次进展
    2021-01-16 09:26

    You will most likely not be happy with this answer, but the only ones that I have seen involve using native code, or executing native commands.

    Edit: I hadn't seen this one before. Have you tried it?: http://code.google.com/p/android-screenshot-library/

    Edit2: Checked that library, and it also is a bad solution. Requires that you start the service from a pc. So my initial answer still holds :)

    Edit3: You should be able to save a view as an image by doing something similar to this. You might need to tweek it a bit so that you get the width/height of the view. (I'm inflating layouts, and specify the width/height when I layout the code)

    View content = getView();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    File file = new File(pathAndFilename);              
    file.createNewFile();
    FileOutputStream ostream = new FileOutputStream(file);
    bitmap.compress(CompressFormat.PNG, 100, ostream);
    ostream.close();
    

提交回复
热议问题