3

I am using the following code to take screen shot of current activity:

View rootview = findViewById(android.R.id.content).getRootView();
rootview.setDrawingCacheEnabled(true);

And save the image on the SD card.

But I am trying to take a screenshot of not just this app, but outside this app as well, I have done some research and found that it's possible only with ROOTED devices, but is there any way that we can take a screen shot of any screen without rooting the device?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Goofy
  • 6,098
  • 17
  • 90
  • 156
  • I am pretty sure it is not, but not 100%. I know that a lot of companies include the functionality as a built in now because so many people wanted it, but it is restricted unrooted. – zgc7009 Jul 29 '14 at 20:37
  • 1
    Hopefully not, for blindingly obvious privacy and security reasons. – CommonsWare Jul 29 '14 at 22:19

5 Answers5

3

Try using reflection to call takeScreenshot() from PhoneWindowManager.java Refer to this link

Refer the following code from here

Do this for PhoneWindowManger.

TelephonyManager telephony = (TelephonyManager) 
  context.getSystemService(Context.TELEPHONY_SERVICE);  
  try {
      Log.v(TAG, "Get getTeleService...");
      Class c = Class.forName(telephony.getClass().getName());
      Method m = c.getDeclaredMethod("getITelephony");
      m.setAccessible(true);
      telephonyService = (ITelephony) m.invoke(telephony);
      telephonyService.silenceRinger();
      Log.v(TAG, "Answering Call now...");
      telephonyService.answerRingingCall();
      Log.v(TAG, "Call answered...");
      //telephonyService.endCall();
  } catch (Exception e) {
   e.printStackTrace();
   Log.e(TAG,
           "FATAL ERROR: could not connect to telephony subsystem");
   Log.e(TAG, "Exception object: " + e);
  }

Android L offers APIs to capture screenshot.refer-https://developer.android.com/reference/android/media/projection/package-summary.html

Community
  • 1
  • 1
rupesh jain
  • 3,410
  • 1
  • 14
  • 22
  • sorry i didnt get you can please show me how that will help me – Goofy Jul 29 '14 at 21:16
  • 1
    refer this link-http://jhshi.me/2014/04/02/get-package-usage-statistics-in-android/.similar thing can be done for taking screenshots.Normally if there is some method which is hidden in framework we use reflection to access it. – rupesh jain Jul 29 '14 at 22:06
1

You are interested in the READ_FRAME_BUFFER permission: http://developer.android.com/reference/android/Manifest.permission.html#READ_FRAME_BUFFER

Problem is that it clearly states: "Not for use by third-party applications."

You are out of luck. This is a security feature (not allowing any app to take screenshots of other apps) that won't go away. You will be limited to rooted devices.

Mikel Pascual
  • 2,202
  • 18
  • 27
1

Here is the code that allowed my screen shot to be stored on sd card and used later for whatever your needs are:

// image naming and path  to include sd card  appending name you choose for file

String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   

// create bitmap screen capture

Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

OutputStream fout = null;
imageFile = new File(mPath);

try {

fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();

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

Then, when you need to access use something like this:

 Uri uri = Uri.fromFile(new File(mPath));
Vaishali Sutariya
  • 5,093
  • 30
  • 32
0

Depends on your purpose. If you need that feature in your application which distributed to playstore, you don't have luck. Without root permission, it's simply not possible.

For test or personal purpose, however, adb will help. You just send some packet to your machine's adb server, you can retrieve device's screen shot.

To do that, you should read out adb client <-> server protocol. framebuffer protocol seems perfect to you.

Or If you familiar with node.js, adbkit will save your time.

chitacan
  • 341
  • 4
  • 9
0

Android L offers APIs to capture screenshot.refer-https://developer.android.com/reference/android/media/projection/package-summary.html

rupesh jain
  • 3,410
  • 1
  • 14
  • 22