使用剪贴板管理器在Android中复制粘贴图像 [英] Copy-Paste image in Android using Clipboard Manager

查看:153
本文介绍了使用剪贴板管理器在Android中复制粘贴图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用剪贴板管理器将图像从我的android应用程序复制到另一个android应用程序.我已经做了很多研究,并阅读了教程,但是它没有t遮盖图像复制部分.下面的代码复制了图像,但是当我尝试粘贴时,仅粘贴了图像的路径.

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't cover the image copying part. The below code which copies image but when I am trying to paste, only the image's path is pasted.

   ContentValues values = new ContentValues(2);
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
    values.put(MediaStore.Images.Media.DATA, "/mnt/sdcard/1.jpg");
    ContentResolver theContent = getContentResolver();
    Uri imageUri = theContent.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    ClipData theClip = ClipData.newUri(getContentResolver(), "Image", imageUri);
    mClipboard.setPrimaryClip(theClip);

我尝试在支持图像粘贴的应用程序中进行粘贴,因此我想问题是复制". 任何答案和建议,将不胜感激.

I tried to past in apps which support image pasting, so I guess the problem is "copy". Any answers and advises would be appreciated.

推荐答案

此代码有效,只需找到合适的应用程序和操作系统即可对其进行测试.

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);

但是,根据我的进一步调查,在大多数Android平台上都无法复制过去的图像,因为原始的android操作系统没有这种功能.上面的代码仅在修改OS的几种情况下有效. 例如,在Samsung Note平板电脑中,它可以工作.您可以将图像粘贴到Polaris办公室. 但是北极星使用的是三星提供的隐藏API,因为该应用程序随设备提供.

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.

这篇关于使用剪贴板管理器在Android中复制粘贴图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆