【问题标题】:How to update the existing sticker pack of Whatsapp如何更新现有的 Whatsapp 贴纸包
【发布时间】:2022-01-19 13:27:46
【问题描述】:

我已经编写了动态添加贴纸包的代码。但是我想知道添加到whatsapp后如何更新贴纸包? 我可以将贴纸文件添加到仅在我的应用程序中列出的包中,但它不会反映在 whatsapp 中。我尝试将文件添加到包发送到whatsapp的相同位置(file:///...)。 我想尝试更新内容提供者。但是怎么做呢?我可以将文件添加到 whatsapp 的 'content://...' uri 还是应该更新我的应用程序的内容提供程序或其他任何内容? 我正在为 react-native 使用 react-native-whatsapp-stickers 模块。

反应原生代码

invoking after adding single sticker from UI
const addOne = (path, packName) =>{
    // log('path ',path[0])
    // log('packName ',packName)
    RNWhatsAppStickers.addSticker(path[0],packName)
    .then(res=>RNWhatsAppStickers.send(packName,packName))
    .then(res=>console.log('response ',res))
}

模块RNWhatsAppStickers的Java代码

 @ReactMethod
    public void send(String identifier, String stickerPackName, Promise promise) {
        Intent intent = new Intent();
        intent.setAction("com.whatsapp.intent.action.ENABLE_STICKER_PACK");
        intent.putExtra(EXTRA_STICKER_PACK_ID, identifier);
        intent.putExtra(EXTRA_STICKER_PACK_AUTHORITY, getContentProviderAuthority(reactContext));
        intent.putExtra(EXTRA_STICKER_PACK_NAME, stickerPackName);

        try {
            Activity activity = getCurrentActivity();
            ResolveInfo should = activity.getPackageManager().resolveActivity(intent, 0);
            if (should != null) {
                activity.startActivityForResult(intent, ADD_PACK);
                promise.resolve("OK");
            } else {
                promise.resolve("OK, but not opened");
            }
        } catch (ActivityNotFoundException e) {
            promise.reject(ERROR_ADDING_STICKER_PACK, e);
        } catch (Exception e) {
            promise.reject(ERROR_ADDING_STICKER_PACK, e);
        }
    }

// saving image to same pack
public static void SaveImage(Bitmap finalBitmap, String name, String identifier) {

        String root = path + "/" + identifier;
        File myDir = new File(root);
        myDir.mkdirs();
        String fname = name;
        File file = new File(myDir, fname);
        if (file.exists()){
            // Log.d("ReactNative","root "+root);
            file.delete();
        }

        try {
            FileOutputStream out = new FileOutputStream(file);
            finalBitmap.compress(Bitmap.CompressFormat.WEBP, 90, out);
            out.flush();
            out.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

请告诉我该怎么做?谢谢

【问题讨论】:

    标签: java flutter react-native kotlin whatsapp


    【解决方案1】:

    我在官方文档上找到了解决方案。添加新图像后,您必须为该包增加 image_data_Version。 要跟踪 image_data_Version,您可以查询应用的 ContentProvider 或将 image_data_Version 存储在某处并进行相应更改。

    【讨论】:

    • 需要进行哪些更改?
    • 在传递 json 数据时,您必须设置 pack 的版本。如果您不知道 json 数据的版本密钥,请查看官方 repo。他们后来添加了版本密钥。
    猜你喜欢
    • 2021-08-15
    • 2019-05-10
    • 1970-01-01
    • 2021-08-26
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 2017-06-14
    • 2019-04-21
    相关资源
    最近更新 更多