android share images from assets folder

It is possible to share files (images including) from the assets folder through a custom ContentProvider

You need to extend ContentProvider, register it in your manifest and implement the openAssetFile method. You can then assess the assets via Uris

    @Override
    public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
        AssetManager am = getContext().getAssets();
        String file_name = uri.getLastPathSegment();

        if(file_name == null) 
            throw new FileNotFoundException();
        AssetFileDescriptor afd = null;
        try {
            afd = am.openFd(file_name);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return afd;
    }

Leave a Comment