如何图像复制到clipboardManager,在Android上的例子吗? [英] How to copy image to clipboardManager on Android, example?

查看:157
本文介绍了如何图像复制到clipboardManager,在Android上的例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要复制存储在资源文件夹到剪贴板管理器的图像稍后在另一个应用程序粘贴,如邮件,whatapp或聊天。
我有研究员severals链接提到的一些可以做到这一点作出的URI到文件中。

这是我得到的最好,somene可以点我的这个工作的例子。

 文件镜像文件=新的文件(文件:///android_asset/coco_001.png);
ContentValues​​值=新ContentValues​​(2);values​​.put(MediaStore.Images.Media.MIME_TYPE,图像/ PNG);
values​​.put(MediaStore.Images.Media.DATA,imageFile.getAbsolutePath());
ContentResolver的theContent = getContentResolver();
乌里imageUri = theContent.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,价值观);
ClipData theClip = ClipData.newUri(getContentResolver(),图像,imageUri);


解决方案

尝试code的这两条线在你code的末尾添加。

  android.content.ClipboardManager剪贴板=(android.content.ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(theClip);

I want to copy an image stored in resources folder to clipboard manager to later be pasted on another app, like mail,whatapp or chat. i have researcher severals links some mention this can be done making an uri to a file.

This is the best i got, can somene point me to a working example of this.

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

解决方案

try to add these two lines of code at the end of your code.

android.content.ClipboardManager clipboard = (android.content.ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);             
clipboard.setPrimaryClip(theClip);

这篇关于如何图像复制到clipboardManager,在Android上的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆