-1

how can I screen capture via android.I mean I want to write a program which make a screenshot of the screen.any link appreciated ,thank you all

Swapnil
  • 654
  • 7
  • 27
sakir
  • 3,391
  • 8
  • 34
  • 50

2 Answers2

3

This is not possible as easily as you'd like it to. There is no official API for that for security reasons.

Here are your options:

  • Using the screencap command line tool: Needs root permission, not installed on all phones
  • Getting the frame buffer: Requires root
  • Using android-screenshot-library: Requires adb connection for start
FD_
  • 12,947
  • 4
  • 35
  • 62
1

I use this code to take a screenshot of MY APP (you can't take a picture of other apps):

@SuppressLint("SimpleDateFormat")
protected final static boolean shoot
(final View v, final String appName)
{
    // Get the bitmap from the view
    v.setDrawingCacheEnabled(true);

    boolean isOK = false;

    final Bitmap bmp = v.getDrawingCache();

    final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd@HHmmss");
    final Calendar cal = Calendar.getInstance();

    // Set file properties
    fileJPG = appName + "_" + sdf.format(cal.getTime());

    /*
    Create a path where we will place our picture in the user's public
    pictures directory. Note that you should be careful about what you
    place here, since the user often manages these files.
    For pictures and other media owned by the application, consider
    Context.getExternalMediaDir().
    */
    final File path =
        Environment.getExternalStoragePublicDirectory
        (
            Environment.DIRECTORY_DCIM + "/Your_App_Name/"
        );

    // Make sure the Pictures directory exists.
    if(!path.exists())
    {
        path.mkdirs();
    }

    final File file = new File(path, fileJPG + ".jpg");

    try
    {
        final FileOutputStream fos = new FileOutputStream(file);
        final BufferedOutputStream bos =
            new BufferedOutputStream(fos, 8192);

        bmp.compress(CompressFormat.JPEG, 85, bos);

        bos.flush();
        bos.close();

        fileJPG = file.getPath();
        isOK = true;
    }
    catch (final IOException e)
    {
        e.printStackTrace();
    }
    return isOK;
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115