5

我想将存储在资源文件夹中的图像复制到剪贴板管理器,以便稍后粘贴到另一个应用程序上,例如邮件、whatapp 或聊天。我有研究人员的几个链接,有些人提到这可以通过将 uri 制作到文件中来完成。

这是我得到的最好的,有人可以指出一个可行的例子。

File imageFile = new File("file:///android_asset/coco_001.png");
ContentValues values = new ContentValues(2);

values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
values.put(MediaStore.Images.Media.DATA, imageFile.getAbsolutePath());
ContentResolver theContent = getContentResolver();
Uri  imageUri = theContent.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  
ClipData theClip = ClipData.newUri(getContentResolver(),"Image", imageUri);
4

1 回答 1

-1

尝试在代码末尾添加这两行代码。

android.content.ClipboardManager clipboard = (android.content.ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);             
clipboard.setPrimaryClip(theClip);
于 2012-11-28T07:37:04.353 回答