A long press on the images on the Internet or in other places gives me the opportunity to copy the image to the clipboard of my device. See here:

Now I want to implement this in my application. What I still have:
the code
Bitmap bitmap = getBitmap(); File file = storeImage(bitmap, name); //Share Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("image/*"); Uri uri = Uri.fromFile(file); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); //Add Copy to Clipboard to choosers Intent clipboard = new Intent(this, CopyToClipboardImageActivity.class); clipboard.setData(uri); Intent chooserIntent = Intent.createChooser(shareIntent, getString(R.string.shareScreenshot)); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{clipboard}); startActivity(chooserIntent);
CopyToClipboardImageActivity
public class CopyToClipboardImageActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Uri uri = getIntent().getData(); if (uri != null) { copyImageToClipboard(uri); Toast.makeText(this, getString(R.string.hinweisInZwischenablageKopiert), Toast.LENGTH_SHORT).show(); }
But this does not work yet. Either it only copies the strange path to the clipboard (see above ^^), or I get the following NullpointerException:
Trying to call the virtual method 'java.lang.String android.net.Uri.getScheme ()' to reference a null object
in this line ClipData theClip = ClipData.newUri(getContentResolver(), "Image", imageUri);
source share