Android Question Sticker4W Lib: Problem creating sticker pack from External Storage

Ferdari

Active Member
Licensed User
Longtime User
Hi everyone, im using the @DonManfred Sticker4W library for creating sticker packs, but it only works with Assets files, is there a way to use or create on-the-fly a sticker pack from the External or Internal storage?

On the official Stickers GitHub they say it is the way:
Expose files that are stored internally as stickers through ContentProvider

If you would like to expose files saved internally or externally and serve these files as sticker. It is possible, but please follow the guidelines in 'Sticker art and app requirements' to make sure the files meets these requirements. As to how to do that, you can take a look at the following code snippet to get an understanding of how that can be done.

B4X:
private AssetFileDescriptor fetchFile(@NonNull Uri uri, @NonNull AssetManager am, @NonNull String fileName, @NonNull String identifier) throws IOException {

    final File cacheFile = getContext().getExternalCacheDir();

    final File file = new File(cacheFile, fileName);

    try (final InputStream open = am.open(identifier + "/" + fileName);

         final FileOutputStream fileOutputStream = new FileOutputStream(file)) {

         byte[] buffer = new byte[1024];

        int read;

        while ((read = in.read(buffer)) != -1) {

            out.write(buffer, 0, read);

        }

    }

    //The code above is basically copying the assets to storage, and servering the file off of the storage.

    //If you have the files already downloaded/fetched, you could simply replace above part, and initialize the file parameter with your own file which points to the desired file.

    //The key here is you can use ParcelFileDescriptor to create an AssetFileDescriptor.

    return new AssetFileDescriptor(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY), 0, AssetFileDescriptor.UNKNOWN_LENGTH);

}

Is there a way to implement this?

A practical use could be: Download an sticker pack and install from the app, or create and encode images saving it to External and then installing the Pack from the app.

Help would be very appreciated.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

asales

Expert
Licensed User
Longtime User
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
Hi @DonManfred,
Please check if you can change this line and make it editable on b4a:
StickerContentProvider.java
Line 54
Java:
Private static final String CONTENT_FILE_NAME = "contents.json";
This line defines the file that are read.

Also if you want to share the lib code, maybe we can look and try to make the changes. if i can update the lib ill return to you with the updates so you can publish it, the thing is helping each other. ;):)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Also if you want to share the lib code, maybe we can look and try to make the changes.
Sure. This is the old Source from the Library. This works with the Files in Assets.
 

Attachments

  • Sticker4W-src.zip
    17.3 KB · Views: 192
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
Hi @DonManfred, this was a challenge for me and high learning, i have some updates and almost done the lib.

I have deleted and created some new classes.

I have some questions to continue development:
How do you change the CONTENT_PROVIDER_AUTHORITY dynamically?
Java:
public static final String CONTENT_PROVIDER_AUTHORITY  = "stickers.app";
Currently only works with static package name "stickers.app"

I compiled the lib and it WORKS!, im testing all the new Methods, i have 80% progress, but stuck on this.
 
Last edited:
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
Can you share the source of what you do it until now?
Now the lib works like this:;
B4X:
    Dim JSON As JSONParser
    Dim Map1 As Map
    Dim JSONString as String
    JSON.Initialize(JSONString) 'it can be a JSON string or file contents.json
    Map1 = JSON.NextObject
 
    Dim StickerPacks As List
 
    StickerPacks = Map1.Get("sticker_packs")

    stpacks.Initialize("",StickerPacks)    ' New method on lib that assigns the packs to ContentProvider
 
    'Test if it assigned the packs from Initialize
    Dim Packs As List = loader.fetchStickerPacks
    For Each Pack As String In Packs
        'It works!
        Log(Pack)
    Next
 
 
    ' Next you can add Pack with:
    stpacks.addStickerPackExisting(NewPack)
 
    ' Or delete Pack with:
    stpacks.deleteStickerPackById(ID)
 
    ' Im stuck on this [B]addStickerPackExisting[/B], figuring what type of data it needs.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
@asales I sent you a DM

I have some questions to continue development:
How do you change the CONTENT_PROVIDER_AUTHORITY dynamically?
It is not related to this thread. If you have any java question then you should create a thread in the java developer questions forum.
The original code is
Java:
        String shauthority = "StickerContentProvider";
        shauthority = getContext().getApplicationInfo().packageName+".stickercontentprovider";
It uses the Contexts Packagename.
 
Upvote 0

Ferdari

Active Member
Licensed User
Longtime User
It is not related to this thread. If you have any java question then you should create a thread in the java developer questions forum.
The original code is
Java:
        String shauthority = "StickerContentProvider";
        shauthority = getContext().getApplicationInfo().packageName+".stickercontentprovider";
It uses the Contexts Packagename.
Thanks @DonManfred, want to see the changes? i'm stuck on how to get the URI from files loaded through JSON String from B4A, i changed code based on StickerMaker source
 
Last edited:
Upvote 0
Top