简体   繁体   English

如何在没有扎根手机的情况下拍摄android屏幕截图而不是自己的活动视图?

[英]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. 我想显示我的android当前屏幕而不是自己当前的活动屏幕。请提供解决方案。

You cannot do this on non-rooted device. 不能在非root用户的设备上执行此操作。 This is one of the cornerstones of Android security - applications cannot interfere with other applications or spy on them. 这是Android安全性的基石之一-应用程序不能干扰其他应用程序或对其进行监视。

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 我建议您尝试: 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 . 我建议您看看Samsung AllShare / Miracast SDK AllShare is Samsung's own extension of MiraCast. AllShare是Samsung自己的MiraCast扩展。 It's like DNLA (if you know what DNLA is). 就像DNLA(如果您知道DNLA是什么)。 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 . 如果搜索没有成功,请查看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. 现在,我意识到您的三星手机没有笔,但是由于三星设备之间有很多TouchWiz共享代码。 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. 如果找到暴露的公共挂钩供spen用来拍摄屏幕快照,则可以在没有该spen的Samsung设备上找到它。

On a side-note, if you're willing to support Tegra-only devices. 附带说明一下,如果您愿意支持仅Tegra设备。 Only some HTC devices and Xiomi devices even use Tegra, so it's not such a big marketshare. 甚至只有一些HTC设备和Xiomi设备使用Tegra,因此市场份额不是很大。 That would seem possible as well: 这似乎也是可能的:

https://play.google.com/store/apps/details?id=net.tedstein.AndroSS 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 . 为此,我建议您研究HTC SDK和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. 请在这里报告,以告诉我们您的发现,无论是正面还是负面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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