6

code snippet

void takeSnapShot() 
    {
        Process process = null;
        try
        {
        process = Runtime.getRuntime().exec("/system/bin/screencap -p /sdcard/snapshot/test_2.png" );

        try
        {
            process.waitFor();
        } catch (InterruptedException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        } catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




    }

I am gettin an empty file saved whereas If i use the same command through adb shell, i get my screen captured.

Any help will be appreciatable

user2298887
  • 61
  • 1
  • 2

2 Answers2

0

Edit: my previous answer was mistaken, any app can use the screen capture command.

It might be a permission issue. Are you sure you have permission to write to sdcard? Check this post, which covers your topic: How to run android system app without root permisson?

Community
  • 1
  • 1
tbkn23
  • 5,205
  • 8
  • 26
  • 46
0

I solved this by adding the following permission to my Manifest.

<uses-permission
    android:name="android.permission.READ_FRAME_BUFFER"
    tools:ignore="ProtectedPermissions"/>

NOTE: This is a protected permission, my application is a system app and also signed using the platform key.

mfleshman
  • 313
  • 4
  • 11