0

I'm following this guide in order to build a stickers app: https://github.com/WhatsApp/stickers/tree/master/Android

What I'm doing in a different way, is getting the json, tray images and sticker files from a web service instead from assets.

Everything is working fine (including adding the stickers to whatsapp) except for one thing: the webp stickers are not showing in the pack detail view (sticker_pack_details.xml).

I'm changing where the sticker file is loaded like this

StickerPreviewAdapter.java

public void onBindViewHolder(@NonNull final StickerPreviewViewHolder stickerPreviewViewHolder, final int i)}
{
    stickerPreviewViewHolder.stickerPreviewView.setImageResource(errorResource);
    //stickerPreviewViewHolder.stickerPreviewView.setImageURI(StickerPackLoader.getStickerAssetUri(stickerPack.identifier, stickerPack.getStickers().get(i).imageFileName));

    String filename = "/data/user/0/com.example.samplestickerapp/files/" + stickerPack.identifier + "/" + stickerPack.getStickers().get(i).imageFileName;
    android.net.Uri stickerURI = android.net.Uri.parse(filename);
    stickerPreviewViewHolder.stickerPreviewView.setImageURI(stickerURI);
}

The commented line fetches the stickers from assets, but I've changed it so the stickers are grabbed from the internal storage.

Am I missing something or looking in the wrong place?

I've also changed readContentFile() and fetchFile()* from StickerContentProvider.java so the sticker is fetched from internal storage rather than assets.

*as stated here: https://github.com/WhatsApp/stickers/blob/master/Android/README.md#expose-files-that-are-stored-internally-as-stickers-through-contentprovider

Matías Cánepa
  • 5,770
  • 4
  • 57
  • 97

1 Answers1

1

I've got it working!!

All credit goes to Meikiem: his comments on his answer pointed me in the right direction

public void onBindViewHolder(@NonNull final StickerPreviewViewHolder stickerPreviewViewHolder, final int i)}
{
    stickerPreviewViewHolder.stickerPreviewView.setImageResource(errorResource);
    //stickerPreviewViewHolder.stickerPreviewView.setImageURI(StickerPackLoader.getStickerAssetUri(stickerPack.identifier, stickerPack.getStickers().get(i).imageFileName));

    String filename = "/data/user/0/com.example.samplestickerapp/files/" + stickerPack.identifier + "/" + stickerPack.getStickers().get(i).imageFileName;

    //Instead of this:
    //android.net.Uri stickerURI = android.net.Uri.parse(filename);

    //I had to do this:
    java.io.File file = new java.io.File(filename);
    android.net.Uri stickerURI = android.net.Uri.fromFile(file);

    stickerPreviewViewHolder.stickerPreviewView.setImageURI(stickerURI);
}
Matías Cánepa
  • 5,770
  • 4
  • 57
  • 97