如何更新现有的 Whatsapp 贴纸包
How to update the existing sticker pack of Whatsapp
我写了动态添加贴纸包的代码。但是我想知道添加到whatsapp后如何更新贴纸包?
我可以将贴纸文件添加到仅在我的应用程序中列出的包中,但它没有反映在 whatsapp 中。我尝试将文件添加到将包发送到 whatsapp 的相同位置 (file:///...)。
我想尝试更新内容提供者。但是怎么做呢?我可以将文件添加到 whatsapp 的 'content://...' uri 还是应该更新我的应用程序的内容提供程序或其他任何内容?
我正在为 react-native 使用 react-native-whatsapp-stickers 模块。
react-native 代码
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))
}
Java 模块代码 RNWhatsAppStickers
@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();
}
}
请告诉我该怎么做?谢谢
我在官方文档上找到了解决方案。添加新图像后,您必须增加该包的 image_data_Version
。
要跟踪 image_data_Version
,您可以查询应用的 ContentProvider 或将 image_data_Version
存储在某处并进行相应更改。
我写了动态添加贴纸包的代码。但是我想知道添加到whatsapp后如何更新贴纸包? 我可以将贴纸文件添加到仅在我的应用程序中列出的包中,但它没有反映在 whatsapp 中。我尝试将文件添加到将包发送到 whatsapp 的相同位置 (file:///...)。 我想尝试更新内容提供者。但是怎么做呢?我可以将文件添加到 whatsapp 的 'content://...' uri 还是应该更新我的应用程序的内容提供程序或其他任何内容? 我正在为 react-native 使用 react-native-whatsapp-stickers 模块。
react-native 代码
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))
}
Java 模块代码 RNWhatsAppStickers
@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();
}
}
请告诉我该怎么做?谢谢
我在官方文档上找到了解决方案。添加新图像后,您必须增加该包的 image_data_Version
。
要跟踪 image_data_Version
,您可以查询应用的 ContentProvider 或将 image_data_Version
存储在某处并进行相应更改。