Example usage for android.content ContentProviderClient openAssetFile

List of usage examples for android.content ContentProviderClient openAssetFile

Introduction

In this page you can find the example usage for android.content ContentProviderClient openAssetFile.

Prototype

public @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri url, @NonNull String mode)
        throws RemoteException, FileNotFoundException 

Source Link

Document

See ContentProvider#openAssetFile ContentProvider.openAssetFile .

Usage

From source file:org.anhonesteffort.flock.sync.addressbook.ContactFactory.java

protected static void addPicture(String path, ContentProviderClient client, Uri pictureUri, VCard vCard)
        throws InvalidComponentException, RemoteException {
    try {//w w  w  .  j  a  v  a2  s. c  om

        AssetFileDescriptor fileDescriptor = client.openAssetFile(pictureUri, "r");
        InputStream inputStream = fileDescriptor.createInputStream();

        Photo photo = new Photo(IOUtils.toByteArray(inputStream), ImageType.JPEG);
        vCard.addPhoto(photo);

    } catch (FileNotFoundException e) {
        // nothing to do...
    } catch (IOException e) {
        throw new InvalidComponentException("caught exception while adding picture", false,
                CardDavConstants.CARDDAV_NAMESPACE, path);
    }
}