Code example for URI

Methods: getScheme, toString

0
		this.context = context;
	} 
 
	@Override 
	protected InputStream getStreamFromOtherSource(URI imageUri) throws IOException {
		String protocol = imageUri.getScheme();
		if (PROTOCOL_ASSETS.equals(protocol)) {
			return getStreamFromAssets(imageUri);
		} else if (PROTOCOL_DRAWABLE.equals(protocol)) {
			return getStreamFromDrawable(imageUri);
		} else { 
			return super.getStreamFromOtherSource(imageUri);
		} 
	} 
 
	private InputStream getStreamFromAssets(URI imageUri) throws IOException {
		String filePath = imageUri.toString().substring(PROTOCOL_ASSETS_PREFIX.length()); // Remove "assets://" prefix from image URI
		return context.getAssets().open(filePath);
	} 
 
	private InputStream getStreamFromDrawable(URI imageUri) {
		String drawableIdString = imageUri.toString().substring(PROTOCOL_DRAWABLE_PREFIX.length()); // Remove "drawable://" prefix from image URI
		int drawableId = Integer.parseInt(drawableIdString);
		BitmapDrawable drawable = (BitmapDrawable) context.getResources().getDrawable(drawableId);
		Bitmap bitmap = drawable.getBitmap();
 
		ByteArrayOutputStream os = new ByteArrayOutputStream();