【问题标题】:Getting no application can do this action on Android while using Codename One share button使用 Codename One 共享按钮时,没有应用程序可以在 Android 上执行此操作
【发布时间】:2017-03-06 04:52:21
【问题描述】:

My Codename One 应用具有 ShareButton,其用法如下:

 // Share this report on social networks (text plus screenshot)
    ShareButton shareReportButton = new ShareButton();
    shareReportButton.setText("Share this report!");
    shareReportButton.getAllStyles().setBorder(
                    RoundBorder.create().rectangle(true));
    FontImage.setMaterialIcon(shareReportButton, FontImage.MATERIAL_SHARE);
    shareReportButton.getStyle().setBgColor(ParametresGeneraux.accentColor);
    shareReportButton.getPressedStyle().setBgColor(ParametresGeneraux.darkPrimaryColor);

    shareReportButton.setTextToShare("I reported this via the great app ABCD "!"
    );
    shareReportButton.setImageToShare(currentReport.getPhotoPath(), ImageIO.FORMAT_PNG);

我在模拟器下按预期工作,但在实际的 Android 4.4 设备上,我得到一个对话框菜单,其中显示“没有应用程序可以执行此操作”。

请注意,可以与本机应用共享照片。

我找不到任何要添加 in the doc 的构建提示。我应该怎么做才能让分享按钮提供一种在社交网络上分享文字+照片的方式?

任何帮助表示赞赏,

问候

编辑

按照@James H 和@Diamond 的回答,图像类型必须设置为mime 类型。因此,将 ImageIO.FORMAT_PNG 替换为“image/jpg”会填充共享菜单。

为了完整起见,请注意文档中的说明

必须使用 FileSystemStorage API 存储图像,并且不应使用 Storage 等其他 API!

因此,即使照片在缓存中,您也必须将其复制到您的主文件夹,然后在 ShareButton 中使用此复制版本。

【问题讨论】:

    标签: share codenameone


    【解决方案1】:

    我认为问题可能是这样的

    setImageToShare(String imagePath, String imageMimeType)
    

    正在寻找不同格式的 Mime 描述,例如:“image/png”

    我不确定 ImageIO.FORMAT_PNG 是否以这种方式工作。查看 JavaDoc 中的示例,它使用:

    sb.setImageToShare(imageFile, "image/png");
    

    【讨论】:

    • 嗨,James H,非常感谢,现在效果更好了。我使用了“image/png”或“image/jpg”,并且能够看到共享菜单已填充!照片未附上,但文字已经存在!
    • 我不确定是否支持图像和文本。我认为是非此即彼。
    • 嗨 @Shai 至少在 Android 4.4 上可以共享文本和图像,这很好!
    • 您可以在 Android 和 iOS 上使用 ShareButton 共享文本和图像。
    • 过去有一个非此即彼的模式,我认为陈在某个时候修复了它。
    【解决方案2】:

    使用本机共享功能并通过执行以下操作检查是否支持本机共享:

    // Share this report on social networks (text plus screenshot)
    Button shareReportButton = new Button("Share this report!");
    shareReportButton.getAllStyles().setBorder(create().rectangle(true));
    FontImage.setMaterialIcon(shareReportButton, FontImage.MATERIAL_SHARE);
    shareReportButton.getStyle().setBgColor(ParametresGeneraux.accentColor);
    shareReportButton.getPressedStyle().setBgColor(ParametresGeneraux.darkPrimaryColor);
    shareReportButton.addActionListener(e -> {
        if (Display.getInstance().isNativeShareSupported()) {
            Display.getInstance().share("I reported this via the great app ABCD ", currentReport.getPhotoPath(), "image/png"); // Or "image/jpg"
        } else {
            ToastBar.showErrorMessage("Your phone doesn't support sharing...");
        }
    });
    

    【讨论】:

    • 嗨,Diamond,也非常感谢!您的解决方案也有效,尽管没有附加照片(照片文件名显示 cacheXYZ.jpg 大小为 1.3KB)。我得看看图片是什么样子的。顺便说一句,与@James H 建议的内容相比,使用本机共享有什么好处?
    • ShareButton 要求您添加默认情况下不存在的其他您想要的服务,但Display.getInstance().share() 允许通过设备上所有可用的 ShareServices 进行共享,而无需单独添加它们。
    • 服务是指 Twitter、Facebook、电子邮件……在我的设备上,这两种解决方案都提供了要使用的服务列表,所以我不明白你的解释。你介意详细说明一下吗?
    • 好吧,那我可能错了……以前我必须通过shareReportButton.addShareService(share) 来添加不存在的服务,这可能已经改变了。
    • 哦,是的,我在 Android 上没有什么特别的事情要做。所有服务都已经存在了!无论如何感谢您的解释。我会将 James H 的答案标记为正确,因为它最接近我的代码,但你的答案也很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2018-02-26
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多