[英]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.