简体   繁体   中英

how to take screen shot of android screen not own activity view without rooted phone?

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.

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM