For example, how to copy an image to clipboardManager on Android?

I want to copy the image stored in the resource folder to the clipboard manager so that it can be pasted into another application, for example, mail, whatapp or chat. I have links for researchers mentioning that this can be done by creating uri for the file.

This is the best I have received, may eventually 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); 
+4
source share
1 answer

try adding these two lines of code to the end of your code.

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

All Articles