7

我有一个 EditText 来输入网络链接。我想预览输入的 URL,类似于 Facebook 中的功能,我们在其中发布链接并会看到页面的图像,标题在顶部,URL 在底部。

如何在 Android 中开发它?

4

1 回答 1

12

在用户在编辑文本中输入链接后使用JSOUP来解析您的链接 OG 元标记(这是 FB 所查看的)刮掉元标记:

这是您希望从最近的纽约时报文章中获得的元信息示例

<meta property="og:url" content="http://www.nytimes.com/2013/03/16/world/europe/pope-francis-praises-benedict-urges-cardinals-to-spread-gospel.html"/>
<meta property="og:type" content="article"/>
<meta property="og:title" content="Vatican Rejects Argentine Accusations Against Pope Francis"/>
<meta property="og:description" content="The Vatican on Friday formally defended Pope Francis’ role in Argentina’s so-called “Dirty War,” amid accusations that he failed to halt abuses of which he had knowledge.">
<meta property="og:image" content="http://graphics8.nytimes.com/images/2013/03/16/world/16vatican/16vatican-superJumbo.jpg"/>
于 2013-03-15T17:56:00.843 回答