如何在Android中添加图像描述和标题(例如图像描述和标题)等元属性

发布于 2025-02-09 12:20:38 字数 192 浏览 1 评论 0原文

我知道可以使用Firebase Deep Linking来实现这一点,但是我发现它对自定义域有点复杂,因此我选择了常规域。但是,我找不到如何添加图像,标题和字幕?另外,URL将是这样的动态:

forms.mysiteName.in/solve/randomformid

I know this can be achieved using Firebase Deep Linking, but I find it a bit too complicated with a custom domain, so I go with the regular one. But, I could not find how do I add an image, title and subtitle for it? Also, the URL will be dynamic like this:

forms.mysitename.in/solve/randomFormId

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雄赳赳气昂昂 2025-02-16 12:20:45

因为在一天结束时,您可以将其作为查询参数传递。请注意,您应该基础64在插值字符串之前编码参数,因为它是无法使用的。

如果您使用 android的uri class 您已经并且可以编写以下内容:

Uri
  .Builder()
  .scheme("https")
  .authority("forms.mysitename.in")
  .appendPath("solve")
  .appendPath("$randomFormId")
  .query("title=$title&description=$description&image=$imageUrl")
  .build()

假设您的图像参数为URL。如果不是URL,则可以在查询参数中使用Base64编码版本,但这不建议


以下代码:

private fun makeUri(): Uri = with(Uri.Builder()) {
val randomFormId = UUID.randomUUID()
val title = "og:meow:My title with spaces and emoji

Because at the end of the day you're handling URI's you can pass them as query parameters. Note that you should base-64 encode the parameters before interpolating the string as it's otherwise unusable.

If you use Android's Uri class that's handled for you already and can write the following:

Uri
  .Builder()
  .scheme("https")
  .authority("forms.mysitename.in")
  .appendPath("solve")
  .appendPath("$randomFormId")
  .query("title=$title&description=$description&image=$imageUrl")
  .build()

Assuming your image parameter is a Url. If it's not a URL you can use the Base64 encoded version into the query parameter but that's not advisable


The following code:

private fun makeUri(): Uri = with(Uri.Builder()) {
    val randomFormId = UUID.randomUUID()
    val title = "og:meow:My title with spaces and emoji ????"
    val description = "A description :)"
    val imageUrl ="https://images.pexels.com/photos/45201/kitty-cat-kitten-pet-45201.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
    scheme("https")
    authority("forms.mysitename.in")
    appendPath("solve")
    appendPath("$randomFormId")
    appendQueryParameter("title", title)
    appendQueryParameter("description", description)
    appendQueryParameter("image", imageUrl)
    build()
}

Log.d("Test", "${makeUri()}")

Prints:

https://forms.mysitename.in/solve/a6d37c1f-ad7d-46f4-87ef-8e77a9159d6a?title=og%3Ameow%3AMy%20title%20with%20spaces%20and%20emoji%20%F0%9F%91%80&description=A%20description%20%3A)&image=https%3A%2F%2Fimages.pexels.com%2Fphotos%2F45201%2Fkitty-cat-kitten-pet-45201.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26dpr%3D1%26w%3D500

Which is a valid Uri.

You can also use this following function to create a new Uri from an old one:

private fun fromUri(
    uri: Uri,
    newTitle: String = uri.getQueryParameter("title") ?: "",
    newDescription: String = uri.getQueryParameter("description") ?: "",
    newImageUrl: String = uri.getQueryParameter("imageUrl") ?: "",
) = with(Uri.Builder()) {
    scheme(uri.scheme)
    authority(uri.authority)
    uri.pathSegments.forEach { pathSegment -> appendPath(pathSegment) }

    // Trick to not add it if it's empty
    newTitle.takeIf { it.isNotEmpty() }?.let { appendQueryParameter("title", it)}
    newDescription.takeIf { it.isNotEmpty() }?.let { appendQueryParameter("description", it)}
    newImageUrl.takeIf { it.isNotEmpty() }?.let { appendQueryParameter("imageUrl", it)}
    build()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文