5

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);
Valleskon
  • 53
  • 1
  • 6

1 Answers1

-1

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);
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
  • Thanks for your answer, but that code i got up there dont work, i can copy plain text based on the examples, but i cant copy the image it just copy the link to the image **/android_asset/coco_001.png** but not the actual image, in my previus reading somene point that you can setup the Uri to have the MIME_TYPE to "image/png", if you try whit a intent to pull a image from camera an in te responce you get the data from the inten.getData() rreturn a Uri that contain the image and that is what you put on the clipboard, but i cant find any real example – Valleskon Nov 29 '12 at 03:31