0

我正在创建一个用于向 WhatsApp 添加自定义贴纸的 android 应用程序。我已按照此示例进行操作,但在向 WhatsApp 添加贴纸时,会显示错误对话框,并显示消息“此贴纸包存在问题,无法添加到 Whatsap”。我得到 onActivity 结果的验证错误是"fd must not be null"。我无法找到此错误的原因。在这种情况下,FD 是什么?

我尝试过的: -我尝试添加发布者电子邮件、网站等所有字段,但仍然出现此错误。

- 对于托盘图像,我在我的资产文件夹中添加了一个 webp 图标,并在托盘图像文件字段中提供了它的名称。

需要什么: - 我从 firebase 获取的自定义贴纸包应该添加到 WhatsApp 中,包括正常和动画。

这是从我的项目创建的 json 文件

[
  {
    "androidPlayStoreLink":"i have added valid playstore link here removed purposely here",
    "animatedStickerPack":false,
    "avoidCache":false,
    "identifier":"50016",
    "imageDataVersion":"",
    "index":"0",
    "isCustom":false,
    "isPremimmum":false,
    "isWhitelisted":false,
    "licenseAgreementWebsite":"",
    "name":"Thanks",
    "privacyPolicyWebsite":"",
    "publisher":"TEST CONTENT",
    "publisherEmail":"1",
    "publisherWebsite":"",
    "stickerMode":0,
    "stickers":[
      {
        "emojis":[

        ],
        "imageFileName":"500161",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500161.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500162",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500162.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500163",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500163.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500164",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500164.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500165",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500165.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500166",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500166.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500167",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500167.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500168",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500168.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"500169",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/500169.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001610",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001610.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001611",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001611.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001612",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001612.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001613",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001613.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001614",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001614.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001615",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001615.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001616",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001616.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001617",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001617.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001618",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001618.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001619",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001619.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001620",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001620.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001621",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001621.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001622",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001622.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001623",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001623.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001624",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001624.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001625",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001625.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001626",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001626.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001627",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001627.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001628",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001628.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001629",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001629.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"5001630",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/50016/5001630.webp"
      }
    ],
    "stickersAddedIndex":30,
    "totalSize":0,
    "trayImageFile":"my_tray_icon.webp"
  },
  {
    "androidPlayStoreLink":"i have added valid playstore link here removed purposely here",
    "animatedStickerPack":true,
    "avoidCache":false,
    "identifier":"60006",
    "imageDataVersion":"",
    "index":"0",
    "isCustom":false,
    "isPremimmum":false,
    "isWhitelisted":false,
    "licenseAgreementWebsite":"",
    "name":"Dogs",
    "privacyPolicyWebsite":"",
    "publisher":"TEST CONTENT",
    "publisherEmail":"1",
    "publisherWebsite":"",
    "stickerMode":0,
    "stickers":[
      {
        "emojis":[

        ],
        "imageFileName":"600061",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600061.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600062",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600062.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600063",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600063.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600065",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600065.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600066",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600066.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600067",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600067.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600068",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600068.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"600069",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/600069.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000610",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000610.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000611",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000611.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000612",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000612.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000613",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000613.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000614",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000614.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000615",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000615.webp"
      },
      {
        "emojis":[

        ],
        "imageFileName":"6000616",
        "size":0,
        "uri":"file:///data/user/0/com.example.myapppackagename/files/60006/6000616.webp"
      }
    ],
    "stickersAddedIndex":15,
    "totalSize":0,
    "trayImageFile":"my_tray_icon.webp"
  }
]

我在这里缺少什么吗?fd 应该在此处添加哪个字段?有人可以帮我解决这个问题。任何帮助将不胜感激。谢谢

4

1 回答 1

0

如果您有自定义 uri,请执行此操作

File file =new File(uri);
                Uri newUri = Uri.fromFile(file);
                getApplicationContext().getContentResolver().openFileDescriptor(newUri,"r" );

在 openAssetFile 的内容提供者类中

 pfd = Objects.requireNonNull(getContext()).getContentResolver().openFileDescriptor(
                                csp.getTrayImageUri(), "r");

如果您对我有任何疑问或在此处发表评论,请执行您的工作

于 2021-07-13T06:15:52.847 回答