Screen capture on Android using Java code

Possible Duplicate:
Android Screenshot

I would like to take screenshots programmatically (and not a screenshot of my presentation) and created an application to take a screenshot of my presentation.

I am trying to capture a screenshot of the device (for example, if the user executed some image file) using Java code (I was thinking about creating a service and a service, we can take a picture, but I'm not sure how to do it).

I found some native code using the fb0 frame buffer, but I really know this and don’t know how to use it.

+2
source share
1 answer

SD-.

:

View content = findViewById(R.id.layoutroot);
content.setDrawingCacheEnabled(true);

:

private void getScreen()
{
    View content = findViewById(R.id.layoutroot);
    Bitmap bitmap = content.getDrawingCache();
    File file = new File( Environment.getExternalStorageDirectory() + "/test.png");
    try 
    {
        file.createNewFile();
        FileOutputStream ostream = new FileOutputStream(file);
        bitmap.compress(CompressFormat.PNG, 100, ostream);
        ostream.close();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

AndroidManifest.

+9

Source: https://habr.com/ru/post/1535885/


All Articles