public void sharePhoto() { Uri uri = albumItem.getUri(this); Intent shareIntent = ShareCompat.IntentBuilder.from(this) .addStream(uri) .setType(MediaType.getMimeType(this, uri)) .getIntent(); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String title = getString(R.string.share_item, albumItem.getType(this)); if (shareIntent.resolveActivity(getPackageManager()) != null) { startActivity(Intent.createChooser(shareIntent, title)); } else { String error = getString(R.string.share_error, albumItem.getType(this)); Toast.makeText(this, error, Toast.LENGTH_SHORT).show(); } }