0

I need to retrieve image copied from webside in native, built-in android web browser. I am wondering what kind of mechanism is used for CopyPaste operations in built-in applications, because it is not "standard" clipboard. Eg. After copying image in browser (copied into clipboard toast is displayed), when pasting into new SMS i can browse "clipboard" content and pick the one I would like to paste. Content can be text, link and image.

In my approach I am using clipboard listener in background service

    listener = new ClipboardManager.OnPrimaryClipChangedListener() {
        @Override
        public void onPrimaryClipChanged() {
            Log.d(LOG_TAG, "Clipboard content changed");
            processClipboardContent();
        }
    };
    manager.addPrimaryClipChangedListener(listener); // ClipboardManager

This works fine for text content copied into the clipboard. However this listener is not notified when copying images in browser. Im using Samsung Galaxy S5 for testing. Any ideas how to retrieve content (probabli URI's) copied in build-in browser?

Antoniossss
  • 31,590
  • 6
  • 57
  • 99

1 Answers1

0

I have tried this one. When I click on the image, it will be copied to clipboard and you can paste it wherever you want. I hope this will work for you.

imgDeletePic.setOnLongClickListener(new OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View v) {
                        // TODO Auto-generated method stub
                        try{
                             ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 
                             ClipData clip = ClipData.newRawUri("Image", Uri.parse("file://" +strFilePath));
                             clipboard.setPrimaryClip(clip);

                             Toast.makeText(DeletePhotoActivity.this, "Sticker copied.", Toast.LENGTH_SHORT).show();
                        } catch(Exception e) {
                            e.printStackTrace();
                        }
                        return false;
                    }
                });
Parth Bhayani
  • 1,894
  • 3
  • 17
  • 35