0

I want to make an app which can capture device screen without root as: https://play.google.com/store/apps/details?id=com.icecoldapps.screenshotultimate

But I can't find the solution. Anyone help me?

Thank you very much.

Tommy
  • 1
  • 2

4 Answers4

1

Programatically you can do so by executing the below command using adb:

adb shell /system/bin/screencap -p /sdcard/img.png

However to do the same from an application you can use the below method:

Process sh = Runtime.getRuntime().exec("su", null,null); //getting superuser permission to access /system/bin
OutputStream  os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII")); //executing the command
os.flush();
os.close();
sh.waitFor();

In /sdcard/ you will have img.png which will be your screen shot.

Zax
  • 2,870
  • 7
  • 52
  • 76
  • Thanks Zax. But when I build and run, get error: java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null – Tommy Sep 11 '13 at 10:28
  • @Tommy: You should not get any exception as long as you are having the super user privileges. I think you are trying on an unrooted device. So try the same on emulator. – Zax Sep 11 '13 at 10:32
  • Yes I run on unrooted device. This app can do it: https://play.google.com/store/apps/details?id=com.icecoldapps.screenshotultimate – Tommy Sep 11 '13 at 10:38
  • Have you added WRITE_EXTERNAL_STORAGE permission for your application? – Zax Sep 11 '13 at 10:41
  • Yes, I do. But this error on: Process sh = Runtime.getRuntime().exec("su", null, null); – Tommy Sep 11 '13 at 11:05
0

From the FAQ of the app:

No “Capture Method” available for my device!

This is normal if your device isn't rooted. It's the way how the Android security model works; it just doesn't allow taking a screenshot on some devices. However, you can enable screenshot functionality on your device by enabling it through a computer. To see how you can do this go to “Screenshot Ultimate” > “Settings” > “Capture methods” > “No capture method help”. You can email the manual to yourself so you can complete it on your computer (Windows, Linux or Mac OSX).

Community
  • 1
  • 1
Melvin
  • 35
  • 4
0

Check if this can help you out. The following code will help you to capture the screen of a particular Layout

RelativeLayout screenShotLayout=(RelativeLayout)findViewById(R.id.ScreenShotLayout);

Bitmap Bitmapimage=Bitmap.createBitmap(screenShotLayout.getWidth(),screenShotLayout.getHeight(), Config.ARGB_8888);
screenShotLayout.setDrawingCacheEnabled(true);
screenShotLayout.buildDrawingCache();
Bitmapimage=screenShotLayout.getDrawingCache();
//Bitmapimage is the screenshot of the layout. Do your stuff with it
Bhavna
  • 836
  • 2
  • 6
  • 19
0
// 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();
}

To access the files :

Uri uri = Uri.fromFile(new File(mPath));
An-droid
  • 6,433
  • 9
  • 48
  • 93