0

这是代码的摘录。我可以编译它,但程序在手机/模拟器上崩溃。

    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");

有人知道该怎么做吗?我想截取屏幕截图并让用户分享,如果他/她喜欢的话。其他一切正常,这只是我无法获得的屏幕截图。

4

1 回答 1

0

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.

This requires either a modded ROM for this purpose or having root privilege to do so. 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'. CM is another that requires 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.

于 2012-07-02T15:20:52.657 回答