如何在Android上将图像复制到clipboardManager,例如?

Val*_*kon 5 android image copy-paste clipboardmanager

我想将存储在资源文件夹中的图像复制到剪贴板管理器,以便稍后粘贴到另一个应用程序上,如mail,whatapp或chat.我有研究员几个链接一些提到这可以做到一个文件的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);
Run Code Online (Sandbox Code Playgroud)

Ali*_*ran -1

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

android.content.ClipboardManager clipboard = (android.content.ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);             
clipboard.setPrimaryClip(theClip);
Run Code Online (Sandbox Code Playgroud)