什么是App多行文字共享意图 [英] What's App multiline text share intent
问题描述
我尝试使用以下代码共享多行文本,但仅出现最后一行.
val sharingIntent = Intent(Intent.ACTION_SEND)
sharingIntent.setType("text/plain")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Found this cool deal! Check it out.")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, TITLE)
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "MRP : $PRICE")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Deal Price : $DEAL_PRICE")
startActivity(Intent.createChooser(sharingIntent, "Share using"))
I tried to share a multi-line text using the following code, but only the last line appears.
val sharingIntent = Intent(Intent.ACTION_SEND)
sharingIntent.setType("text/plain")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Found this cool deal! Check it out.")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, TITLE)
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "MRP : $PRICE")
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Deal Price : $DEAL_PRICE")
startActivity(Intent.createChooser(sharingIntent, "Share using"))
推荐答案
调用putExtra(key, value)
时,先前放在同一key
下的任何值都会被清除.尝试放置一个包含所有所需文本的字符串:
When you call putExtra(key, value)
, any value previous put under the same key
gets wiped out. Try putting a single string that contains all the text you want:
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Found this cool deal! Check it out.\n" +
TITLE + "\n" +
"MRP : $PRICE\n" +
"DEAL PRICE : $DEAL_PRICE");
对于HTML内容,您需要向我们展示您使用的代码.但是,您可能不想使用fromHtml()
.将HTML转换为样式文本,我怀疑这不是WhatsApp期望接收的内容.尝试仅发送具有正确MIME类型的原始HTML.
As for the HTML content, you'll need to show us the code you used. However, you probably don't want to use fromHtml()
; that converts HTML to styled text, which I suspect is not what WhatsApp expects to receive. Try just sending the raw HTML with the correct MIME type.
这篇关于什么是App多行文字共享意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!