imageview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
// android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
// clipboard.setText(CopyText);
// Toast.makeText(getApplicationContext(), "Text Copied to Clipboard", Toast.LENGTH_SHORT).show();
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
Bitmap b = BitmapFactory.decodeResource(getResources(),R.drawable.chandigarh);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(),
b, "Title", null);
Uri imageUri = Uri.parse(path);
ClipData.Item item = new ClipData.Item(imageUri);
ClipData data = new ClipData("label", new String[]{"image/jpeg"}, item);
// ClipData theClip = ClipData.newUri(getContentResolver(), "Image", imageUri);
clipboard.setPrimaryClip(data);
Log.e("copy", String.valueOf(data));
Toast.makeText(MainActivity.this, "copy to clipboard", Toast.LENGTH_SHORT).show();
}
//your stuff
return true;
}
});
我想在长按时复制图像。以上是我的代码但我的问题是,当我只粘贴uri
时显示。图像不会被复制。请告诉我怎么做?