从其他应用分享的链接中获取数据?

时间:2018-01-31 11:20:17

标签: android

我们都非常熟悉 YouTube 应用中分享选项中的 复制链接 选项。当我们将其粘贴到 Facebook WhatsApp 时,会将其转换为链接,其中包含标题,缩略图,内容等详细信息。我期待在我的应用程序中实现这一点。但我找不到任何相关内容。

1 个答案:

答案 0 :(得分:0)

使用此库: https://github.com/LeonardoCardoso/Android-Link-Preview

<强>实例化

import com.leocardz.link.preview.library.TextCrawler;
// ...
// Create an instance of the TextCrawler to parse your url into a preview.
TextCrawler textCrawler = new TextCrawler();

// ..

// Create the callbacks to handle pre and post exicution of the preview generation.
LinkPreviewCallback linkPreviewCallback = new LinkPreviewCallback() {
    @Override
    public void onPre() {
        // Any work that needs to be done before generating the preview. Usually inflate 
        // your custom preview layout here.
    }

    @Override
    public void onPos(SourceContent sourceContent, boolean b) {
        // Populate your preview layout with the results of sourceContent.
    }
};

生成预览

textCrawler.makePreview( linkPreviewCallback, url);