Android的 - 将图片复制到剪贴板,任何人有这方面的工作?剪贴板、方面、工作、图片

2023-09-06 14:48:58 作者:最好别惹我

我想从我的APK复制影像文件到剪贴板。

I am trying to copy a image file from my apk to the clipboard.

下面是我很接近它时(大概,我使用的本地内容提供商是出了问题的范围。

Here is how I am approaching it (roughly, i'm using a content provider locally which is out of the scope of the question.

        ClipboardManager mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ContentValues values = new ContentValues(2);
        values.put(MediaStore.Images.Media.MIME_TYPE, "Image/jpg");
        values.put(MediaStore.Images.Media.DATA, filename.getAbsolutePath());
        ContentResolver theContent = getContentResolver();
        Uri imageUri = theContent.insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
        ClipData theClip = ClipData.newUri(getContentResolver(), "Image", imageUri);
        mClipboard.setPrimaryClip(theClip);

有了这个code两件事情可能发生:

With this code two things can happen:

1)java.lang.IllegalStateException:无法创建新的文件2)当粘贴只粘贴了URI本身,而不是图像(即使在兼容的应用程序)

1) java.lang.IllegalStateException: Unable to create new file 2) When pasting it only pastes the URI itself, not the image (even in compatible apps)

我没有看到任何人在Android上工作得到图​​像粘贴任何例子,我已经寻找一个答案广泛,无论在谷歌和堆栈溢出。

I don't see any example of anyone getting image pasting on android working, and I have searched for an answer extensively, both on google and stack overflow.

任何人都可以在这方面帮助?我真的AP preciate某人的帮助在这里。

Can anyone help with this? I would really appreciate someones assistance here.

PS:如果它只是不可能做我也想知道,省得浪费了时间在这

PS: If it's just not possible to do I would also like to know that, to save wasting anymore time on this.

谢谢!

推荐答案

有任何迹象表明,这样的功能在Android的支持。

There is no indication that such functionality is supported in Android.

该行为是正确的,URI是在复制的数据不是位图。

The behavior is correct and the uri is the copied data not the bitmap.

这取决于是否有地方要粘贴在可以处理这个URI。

It depends on whether the place you are pasting in can handle this uri.