B4A Library Add your own StickerPack to Whatsapp - Sticker4W


Licensed User
If you would like to design your own stickers for WhatsApp, you can package them in an Android app. You will need to distribute your app via the Google Play Store or another mechanism. Users who download and install your sticker app will be able to add your stickers to their WhatsApp sticker picker/tray, and start sending those stickers from within WhatsApp. A separate app is necessary and it will reside on your phone's home screen just like any other app. Stickers on WhatsApp must be legal, authorized, and acceptable. Learn more about acceptable use of our services at https://www.whatsapp.com/legal/#terms-of-service.

Author: DonManfred
Version: 0.17
  • ContentFileParser
    • Functions:
      • Initialize (EventName As String)
      • parseStickerPacks (contentsInputStream As java.io.InputStream) As java.util.List
      • verifyStickerPackValidity (stickerPack As com.sticker4w.StickerPack)
  • StickerPackLoader
    • Functions:
      • fetchStickerAsset (identifier As String, name As String, contentResolver As android.content.ContentResolver) As Byte()
      • fetchStickerPacks As java.util.List
      • getStickerAssetUri (identifier As String, stickerName As String) As android.net.Uri
      • Initialize (EventName As String)
  • StickerProvider
    • Functions:
      • fetchStickerAsset (identifier As String, name As String, contentResolver As android.content.ContentResolver) As Byte()
      • fetchStickerPacks (context As android.content.Context) As java.util.ArrayList
        Get the list of sticker packs for the sticker content provider
      • getStickerAssetUri (identifier As String, stickerName As String) As android.net.Uri
      • Initialize (EventName As String, Authority As String)
    • Properties:
      • Authority As String
      • StickerPackList As java.util.List [read only]

A few steps are required for your Stickers can be added to Whatsapp.
- See the tips for file-size redicing and creating webp Pictures.
- the contents.json must be in the Files folder.
- the pictures for the stickerpacks must be in a subfolder in the files folder. See Whatsapp-Documentation and Example.
- Add this to your Manifest
    android:readPermission="com.whatsapp.sticker.READ" />
Add this Inline Java code to your Starter Service
#if Java
public static class MyContentProvider extends com.sticker4w.StickerContentProvider {
#End If
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private ion As Object
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim contparser As ContentFileParser
    Dim loader As StickerPackLoader
    Dim prov As StickerProvider
    Private Button3 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    ' From here the methods are not really needed
    Dim instr As InputStream
    instr = File.OpenInput(File.DirAssets, "contents.json")
    Dim packs As List = loader.fetchStickerPacks
End Sub

Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ion_Event (MethodName As String, Args() As Object) As Object
    Log($"ion_Event(${MethodName}, ${Args(0)}, ${Args(1)})"$)
    If Args(1) <> Null Then
        Dim in As Intent = Args(1)
        If in.HasExtra("validation_error") Then
            Dim info As String = in.GetExtra("validation_error")
            Log($"Validation-Error: ${info}"$)
        End If
    End If
    'Args(0) = resultCode
    'Args(1) = intent
    Return Null
End Sub
Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Sub GetBA As Object
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    Return jo.GetField("processBA")
End Sub

Sub Button3_Click
    Dim in As Intent
    in.Initialize("com.whatsapp.intent.action.ENABLE_STICKER_PACK", "")
    in.putExtra("sticker_pack_id", "1") ' Identifier of the StickerPack. The Files of this pack must be in a subfolder named "1" in the Filesfolder. Depends on the entry in the json file
    in.putExtra("sticker_pack_authority", "de.donmanfred.sticker.stickercontentprovider")
    in.putExtra("sticker_pack_name", "Cuppy")
    in.Flags = 1
End Sub
Please read the README about anything about this Whatsapp feature.

This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate for my work to write the wrapper (You can donate any amount you want :))


Last edited:

Douglas Farias

Licensed User


Active Member
Licensed User
Donation Details
Confirmation number: 43F39249KX0296809
Purpose: DonManfred B4A-Forum
Reference: DonManfredDonate

Good Job!! Thank you for many products for our B4A


Active Member
Licensed User
I'm having problems on Android 4.2 and 4.3 devices @DonManfred, when the app open it closes with this error registered on my Developer Console:
  at com.sticker4w.StickerContentProvider.onCreate (StickerContentProvider.java:104)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1214)
  at android.content.ContentProvider.attachInfo (ContentProvider.java:1189)
  at android.app.ActivityThread.installProvider (ActivityThread.java:5155)
  at android.app.ActivityThread.installContentProviders (ActivityThread.java:4761)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:4675)
  at android.app.ActivityThread.access$1400 (ActivityThread.java:165)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1386)
  at android.os.Handler.dispatchMessage (Handler.java:99)
  at android.os.Looper.loop (Looper.java:137)
  at android.app.ActivityThread.main (ActivityThread.java:5455)
  at java.lang.reflect.Method.invokeNative (Native Method)
  at java.lang.reflect.Method.invoke (Method.java:525)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1187)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1003)
  at dalvik.system.NativeStart.main (Native Method)

Can you help me solve this? all other android devices worked like charm!

Thank you.

Ibrahim Saleh

Licensed User
@DonManfred, Please Help with the Sample Example.. It shown me this error

Logger connected to: TECNO MOBILE LIMITED TECNO KB7j
--------- beginning of crash
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
ion_Event(ResultArrived, 0, Intent { (has extras) })
Validation-Error: Third party pack cannot be found likely because the corresponding app is restricted, sdk: 28 ,power saving mode: true
** Activity (main) Resume **