【问题标题】:Download to folder/files android apps下载到文件夹/文件 android 应用程序
【发布时间】:2015-02-28 11:34:19
【问题描述】:

我的问题是我在实践中使用的是 pdf 文件。我没有将它们添加到我的应用程序中。我想从 ftp 或 URL 下载 pdf 文件。我不知道解决方案。我尝试了很多 ftp 代码和 URL 代码。我想要的只是,当您从 URL 或 FTP 地址按下 sdcard 文件的按钮以进行下载时。感谢您的帮助。

【问题讨论】:

  • 欢迎来到 SO。请尝试包含尽可能多的信息,以使用户能够帮助您。通常用户会假设,您已经在代码中尝试过任何东西。请也包括在内。任何提供起点的东西都会帮助其他人帮助你。目前很难解读问题是什么,以及用例可能是什么。
  • 感谢您的帮助。我尝试添加其他信息。

标签: java android file ftp download


【解决方案1】:

这段代码对我有用

   public void onClick(View v) {

        PrintAttributes printAttrs = new PrintAttributes.Builder().
                setColorMode(PrintAttributes.COLOR_MODE_COLOR).
                setMediaSize(PrintAttributes.MediaSize.NA_LETTER).
                setResolution(new PrintAttributes.Resolution("zooey", PRINT_SERVICE, 300, 300)).
                setMinMargins(PrintAttributes.Margins.NO_MARGINS).
                build();
        PdfDocument document = new PrintedPdfDocument(DynamicPDFHelloWorld.this, printAttrs);
        // crate a page description
        PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(300, 300, 1).create();
        // create a new page from the PageInfo
        PdfDocument.Page page = document.startPage(pageInfo);
        // repaint the user's text into the page
        View content = findViewById(R.id.textarea);

        content.draw(page.getCanvas());
        content.draw(edt.getText().toString().);
        // do final processing of the page
        document.finishPage(page);
        // Here you could add more pages in a longer doc app, but you'd have
        // to handle page-breaking yourself in e.g., write your own word processor...
        // Now write the PDF document to a file; it actually needs to be a file
        // since the Share mechanism can't accept a byte[]. though it can
        // accept a String/CharSequence. Meh.
        try {
            File f = new File(Environment.getExternalStorageDirectory().getPath() + "/pruebaAppModerator.pdf");
            FileOutputStream fos = new FileOutputStream(f);
            document.writeTo(fos);
            document.close();
            fos.close();
        } catch (IOException e) {
            throw new RuntimeException("Error generating file", e);
        }

    }
});

【讨论】:

  • 我试过了。但我不明白这一行“content.draw(edt.getText().toString().);”以及如何使用 ftp 或 url 链接。
  • @GOKHAN TEBRIZCIK 其编辑文本及其在 pdf 文件中的绘制
猜你喜欢
  • 1970-01-01
  • 2013-06-17
  • 2014-02-17
  • 2021-12-04
  • 2022-11-19
  • 2021-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多