2

I have written code.

public static void loadBitmapFromView(Context context, View v) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics(); 
    v.measure(MeasureSpec.makeMeasureSpec(dm.widthPixels, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(dm.heightPixels, MeasureSpec.EXACTLY));
    v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
    Bitmap returnedBitmap = Bitmap.createBitmap(v.getMeasuredWidth(),
            v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(returnedBitmap);
    v.draw(c);

    takeScreen(returnedBitmap);
}

public static void takeScreen(Bitmap bitmap) {
    //Bitmap bitmap = ImageUtils.loadBitmapFromView(this, view); //get Bitmap from the view
    String mPath = Environment.getExternalStorageDirectory() + File.separator + "screen_" + System.currentTimeMillis() + ".jpeg";
    File imageFile = new File(mPath);

    try {
        OutputStream fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

where view is

View v1 = getWindow().getDecorView().findViewById(android.R.id.content).getRootView();

But this take our application's current activity screen shot. I want to screen of my android current screen not my own current activity.Please provide solution.

App Kart
  • 924
  • 2
  • 13
  • 24

2 Answers2

0

You cannot do this on non-rooted device. This is one of the cornerstones of Android security - applications cannot interfere with other applications or spy on them.

Taking another application screenshot is essentially spying. As an example, imagine you have some funny game or useless utility downloaded and installed from not very trusted source. If taking screenshot of not-own activity was possible, that game would have been able to take screenshot of you entering banking password in web browser and send it back home to evil developer of that app. That would be quite a disaster, wouldn't it?

mvp
  • 111,019
  • 13
  • 122
  • 148
  • But u can tried app https://play.google.com/store/apps/details?id=jp.tomorrowkey.android.screencaptureshortcutfree – App Kart Dec 22 '13 at 06:18
  • It does not seem to support generic Android device - maybe it is using some backdoor present on Galaxy devices? – mvp Dec 22 '13 at 06:20
  • I have samsung pop device it is working fine on this deviice. – App Kart Dec 22 '13 at 06:21
  • This utility must hold `READ_FRAMEBUFFER` permission and must be signed by Samsung certificate that is present in Samsung ROMs. Read [more here](http://stackoverflow.com/questions/12462944/how-to-take-a-screenshot-of-other-app-programmatically-without-root-permission). – mvp Dec 22 '13 at 06:27
  • Thanks, i am downloading samsung sdk then i will try. – App Kart Dec 22 '13 at 06:32
  • @mvp : I have downloaded samung sdk and configure in eclipse.Now next question is that how to read frame buffer and convert into bitmap.so that we can take screen shots. – App Kart Dec 22 '13 at 07:32
  • That's the whole point of my answer - you can't! For this to work, your app must be signed by Samsung itself - it obviously wouldn't do that for you. – mvp Dec 22 '13 at 07:43
0

Since you proved that there was already a third party app (not a samsung app) that can take screenshots of any app on some Samsung devices.

I'd suggest you try: http://developer.samsung.com/home.do

If there is nothing obvious in their sdks about taking screenshots. I'd suggest you take a look at the Samsung AllShare/Miracast SDK. AllShare is Samsung's own extension of MiraCast. It's like DNLA (if you know what DNLA is). It allows a developer/or a user to project wirelessly their screen on a TV (that supports the protocol).

If that search doesn't go anywhere, take a look at the s.pen sdk. And try to see if they exposed a way to take screenshots for third party developers with the Samsung pen. Now I realize your samsung phone doesn't have a pen, but since there is a lot of TouchWiz shared code between Samsung devices. If you find an exposed public hook for the spen to use to take screenshots, you may be able to find one on Samsung devices that do not have the spen.

On a side-note, if you're willing to support Tegra-only devices. Only some HTC devices and Xiomi devices even use Tegra, so it's not such a big marketshare. That would seem possible as well:

https://play.google.com/store/apps/details?id=net.tedstein.AndroSS

For that, I'd suggest you investigate the HTC SDK and the Nvidia Tegra Development Pack. I'm sorry I don't have more time to look into any of these solutions for you. Please report back here to tell us your findings, whether they are positive or negative.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49