【问题标题】:How can the application user save data to one of his own cloud storage?应用程序用户如何将数据保存到自己的云存储之一?
【发布时间】:2019-06-11 08:17:40
【问题描述】:

在我的 cn1 应用程序中,我想让用户备份自己的云存储成为可能。例如,您自己的 Dropbox 帐户。

我在 WEB 上寻找解决方案。我认为我发现的(dropbox-codenameone-sdk)我只能管理一个已知帐户,因为我需要知道consumerSecret和consumerKey。当我编写代码时,我不知道实际的用户帐户信息。 基于其他应用程序的操作,我假设我必须登录到实际用户他的帐户(例如 Dropbox)。

请帮助我可以执行哪些 API 调用。

【问题讨论】:

    标签: file-upload cloud storage codenameone


    【解决方案1】:

    在 Display 中使用 Share API。您可以使用 zip cn1lib 压缩数据并将其保存在文件系统中的文件中,然后使用共享 API 让用户选择一个本地应用程序来共享它。在模拟器上它会有电子邮件/facebook 等选项,但在设备上你应该有更多选项。

    【讨论】:

    • 非常感谢您的建议。这个机会避开了我的注意。现在很明显了。
    • 嗨,我如何共享与图像不同类型的文件?无论我设置什么 mime 类型,模拟器都会将其视为图像。在 Android 手机上,文件名带有前缀 (IMG_...) 以附加到邮件或发送到 DropBox。因此,找不到该文件。请帮忙。
    • 本机设备的行为与模拟器非常不同。您需要在那里使用 API。
    • 您好,我无法附加图片和 sn-p 作为评论。请在下面阅读我的回答。
    • 模拟器假定正确的图像在那里失败但因为它在设备上工作我没有看到问题?仅供参考,您需要编辑问题而不是添加答案。
    【解决方案2】:

    我认为我正确地使用了 API。虽然我没有正确设置手机上的文件访问权限。

    但是,错误发生在模拟器中。

    我的安卓手机上的邮件和DropBox共享成功。 我不喜欢文件获得前缀(IMG_20200112_204126_)。我可以更改吗?

    我包括屏幕截图和代码 sn-p。

    最好的问候,彼得

    public ShareForm(Resources resourceObjectInstance, Form parentForm) {
    this.parentForm = parentForm; 
    this.theme = resourceObjectInstance;
    
    Layout layout = new BoxLayout(BoxLayout.Y_AXIS);
    setLayout(layout);
    
    getToolbar().setBackCommand("", e -> {
        this.parentForm.showBack();
    });
    
    /* file exist on simulator */
    /*        String filePath = FileSystemStorage.getInstance().getAppHomePath() + "temp/vendeg_201807011754.json"; */
    /* file exist on phone */
    String filePath = "file:///storage/emulated/0/Download/stratos.pdf";
    
    String mimeType = "application/octet-stream";
    
    boolean exist = FileSystemStorage.getInstance().exists(filePath);
    long size = FileSystemStorage.getInstance().getLength(filePath);
    
    SpanLabel spanLabel0 = new SpanLabel("File path: " + filePath);
    SpanLabel spanLabel1 = new SpanLabel("File exist: " + exist);
    SpanLabel spanLabel2 = new SpanLabel("File size: " + size);
    
    ShareButton shareButton = new ShareButton();
    shareButton.setText("Share data (ShareButton)");
    shareButton.addActionListener(e-> {
        shareButton.setImageToShare(filePath, mimeType);
        shareButton.actionPerformed(e);
    });
    
    
    Button shareButton1 = new Button("Share data (Share API in Display)");
    FontImage.setMaterialIcon(shareButton1, FontImage.MATERIAL_SHARE);
    shareButton1.addActionListener(e -> {
        Display.getInstance().share(null, filePath, mimeType, shareButton1.getBounds(new Rectangle()));
    });
    
    addComponent(spanLabel0);
    addComponent(spanLabel1);
    addComponent(spanLabel2);
    addComponent(shareButton);
    addComponent(shareButton1);
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 1970-01-01
      相关资源
      最近更新 更多