【问题标题】:Getting shared data with photo and text获取包含照片和文本的共享数据
【发布时间】:2016-11-18 13:27:02
【问题描述】:

我想在 WhatsApp 中将数据共享到我的应用程序中:

当我在自己的应用程序中尝试时,我只会得到文本(“签出...”)。 如何获取其余数据:图片、标题、描述和网站地址?

 Intent intent = getIntent();
 String action = intent.getAction();
 String type = intent.getType();
 if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
        } else if (type.startsWith("image/")) {
            handleSendImage(intent); // Handle single image being sent
        }
 } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
        if (type.startsWith("image/")) {
            handleSendMultipleImages(intent);
        }
 }

我只收到带有 EXTRA_TEXT 的 ACTION_SEND。

【问题讨论】:

  • 该图像是从您共享的链接中附加的。
  • @KirankumarZinzuvadia 所以我可以在后端对链接进行采样并手动创建?

标签: android share intentfilter android-sharing data-sharing


【解决方案1】:

您可以流式传输图像以共享图像。但主要取决于您选择共享的应用程序是否支持图像流共享。

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));

查看此链接以了解有关共享选项的信息。

https://guides.codepath.com/android/Sharing-Content-with-Intents

要从其他应用接收共享数据,请查看此链接:

https://developer.android.com/training/sharing/receive.html

【讨论】:

  • 谢谢,但我想从其他应用获取数据而不是发送。
【解决方案2】:

我最后这样做的方式是在后端解析链接元数据标签并将详细信息发送到应用程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 2012-08-09
    • 1970-01-01
    相关资源
    最近更新 更多