Copy-Paste image in Android using Clipboard Manager

前端 未结 1 1885
[愿得一人]
[愿得一人] 2020-12-30 09:36

I would like to copy image from my android application to the other android application using clipboard manager. I have researched a lot and read this tutorial but it doesn\

相关标签:
1条回答
  • 2020-12-30 09:48

    This code works, just find appropriate app and OS to test it.

        ClipboardManager mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        ContentValues values = new ContentValues(2);
        values.put(MediaStore.Images.Media.MIME_TYPE, "Image/jpg");
        values.put(MediaStore.Images.Media.DATA, filename.getAbsolutePath());
        ContentResolver theContent = getContentResolver();
        Uri imageUri = theContent.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        ClipData theClip = ClipData.newUri(getContentResolver(), "Image", imageUri);
        mClipboard.setPrimaryClip(theClip);
    

    Edit: According to my further investigations, however, in most of Android platforms the image copy past is not possible because original android OS does not have such a feature. The code above works only for several cases where the OS is modified. For example, in Samsung Note tablet it works. And you can past the image in Polaris office. But Polaris is used the hidden API provided by Samsung, as that app comes with devices.

    0 讨论(0)
提交回复
热议问题