简体   繁体   English

捕获屏幕截图并与社交媒体共享

[英]Capture a screenshot and share it with social media

Here is an excerpt of the code. 这是代码的摘录。 I can compile it, but the program crashes on the phone/emulator. 我可以编译它,但是程序在电话/模拟器上崩溃。

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

    String path = Images.Media.insertImage(getContentResolver(), bitmap,
            "title", null);
    Uri screenshotUri = Uri.parse(path);

    final Intent socialIntent = new Intent(Intent.ACTION_SEND);
    socialIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    socialIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
    socialIntent.setType("image/png");

Anyone know how to do it? 有人知道怎么做吗? I want to capture a screenshot and let the user share it if he/she likes to. 我想捕获一个屏幕截图,并让用户共享(如果他/她愿意)。 Everything else work, it's just the screenshot I cannot get. 其他一切正常,这只是我无法获得的屏幕截图。

The only way a screenshot can be obtained is by having direct access to the frame-buffer which is at the kernel level, this in turn requires rooted access to accomplish this and to pull in the data from there to make up the graphics that is the screen itself. 截屏的唯一方法是直接访问内核级别的帧缓冲区,这反过来又需要root用户访问权限才能完成,并从那里获取数据以构成图形。屏幕本身。

This requires either a modded ROM for this purpose or having root privilege to do so. 为此,需要经过修改的ROM或具有root特权。 Sony, I know, do it, they have that facility in place to do so without root as the ROM is modified, in the power menu, there is an option 'Take Screenshot'. 我知道,Sony做到了,因为有了ROM修改,他们已经拥有了无需root即可执行此操作的功能,在电源菜单中,有一个“ Take Screenshot”选项。 CM is another that requires root. CM是另一个需要root的用户。

There is a facility available in ICS that has the programmatic API available to do this, see this answer , but with earlier versions, you're out of luck. ICS中提供了一种工具,该工具具有可用于此目的的编程API,请参见此答案 ,但是对于早期版本,您很不走运。

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

相关问题 如何制作一个功能以在社交媒体上分享内容? - How to make a feature to share content in social media? 如何使用位图将图像分享到社交媒体? - How to share image to social media with bitmap? Oracle MAF社交媒体共享和默认共享面板 - Oracle MAF social media sharing and the default share panel Android Share Intent选择器 - 与Facebook / Twitter共享文本社交媒体等 - Android Share Intent chooser - Sharing TEXT with Facebook/Twitter Social media etc 致命异常:main java.lang.NullPointerException:尝试将图像共享到社交媒体意图Android时为uriString - FATAL EXCEPTION: main java.lang.NullPointerException: uriString while trying to share image to social media intent Android Window 8 OS 中的屏幕截图 - Screenshot capture in Window 8 OS 捕获活动窗口的屏幕截图 - Capture screenshot of Active Window 使用htmlunitdriver捕获屏幕截图? - Capture screenshot using htmlunitdriver? 无法捕获硒中的屏幕截图 - Unable to capture screenshot in selenium 如何使用 Android 共享意图选择器 (ACTION_SEND) 收听/捕捉社交媒体共享的成功事件? - How do I listen/catch success events of social media sharing using Android Share Intent Chooser (ACTION_SEND)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM