Add your own StickerPack to Whatsapp - Sticker4W

DonManfred

Expert
Licensed User
Longtime 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.

Sticker4W
...|https://www.b4x.com
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]

ATTENTION:
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
B4X:
AddApplicationText(
<provider
    android:name="${applicationId}.starter$MyContentProvider"
    android:authorities="${applicationId}.stickercontentprovider"
    android:enabled="true"
    android:exported="true"
    android:readPermission="com.whatsapp.sticker.READ" />
)

Add this Inline Java code to your Starter Service
B4X:
#if Java
public static class MyContentProvider extends com.sticker4w.StickerContentProvider {
}
#End If

B4X:
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:
    Activity.LoadLayout("Layout1")
  
  
    ' From here the methods are not really needed
    contparser.Initialize("")
    Dim instr As InputStream
    instr = File.OpenInput(File.DirAssets, "contents.json")
    Log(contparser.parseStickerPacks(instr))
    loader.Initialize("")
    Log("loader.fetchStickerPacks")
    Log(loader.fetchStickerPacks)
    Dim packs As List = loader.fetchStickerPacks
    Log(packs.Size)
    Log(loader.getStickerAssetUri("1","Cuppy"))
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)
        Log(in.GetData)
        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)
    jo.InitializeStatic(cls)
    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
    'Try
    StartActivityForResult(in)
 
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 :))
 

Attachments

  • Sticker4WV0.17.zip
    26.6 KB · Views: 737
  • Sticker4WV0.2.zip
    22.8 KB · Views: 745
  • Sticker4WhatsappEx.zip
    320.4 KB · Views: 883
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
hi @DonManfred
its possible make your example run in debug ?
when i test it in debug show me the app stoped work and no logs.
in release this works fine.

edit: i found this.
#DebuggerForceStandardAssets: true

thx
 
Last edited:

tuhatinhvn

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

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

Ferdari

Active Member
Licensed User
Longtime 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:
B4X:
java.lang.NoClassDefFoundError:
 
  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

Member
Licensed User
Longtime 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 **
content://de.donmanfred.sticker42.stickercontentprovider/metadata
[com.sticker4w.StickerPack@776f91f]
loader.fetchStickerPacks
[com.sticker4w.StickerPack@a89b46c]
1
content://de.donmanfred.sticker42.stickercontentprovider/stickers_asset/1/Cuppy
** 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 **
 

Ferdari

Active Member
Licensed User
Longtime User
@DonManfred I'm going to make an online sticker maker. So I have to read the stickers from the internal storage. please help me?
i developed my own sticker lib, that can read from every storage, add and delete stickers, if you are interested send me a PM

and preparing an update for animated stickers...
 
Top