相关疑难解决方法(0)

Android下载二进制文件问题

我在从我的应用程序中下载二进制文件(视频)时遇到问题.在Quicktime中,如果我直接下载它可以正常工作但通过我的应用程序不知何故它搞砸了(即使它们在文本编辑器中看起来完全相同).这是一个例子:

    URL u = new URL("http://www.path.to/a.mp4?video");
    HttpURLConnection c = (HttpURLConnection) u.openConnection();
    c.setRequestMethod("GET");
    c.setDoOutput(true);
    c.connect();
    FileOutputStream f = new FileOutputStream(new File(root,"Video.mp4"));


    InputStream in = c.getInputStream();

    byte[] buffer = new byte[1024];
    int len1 = 0;
    while ( (len1 = in.read(buffer)) > 0 ) {
         f.write(buffer);
    }
    f.close();
Run Code Online (Sandbox Code Playgroud)

java android download httpurlconnection fileoutputstream

71
推荐指数
4
解决办法
8万
查看次数

Phonegap如何在Android应用程序中下载和打开pdf文件

最近我正在开发一个android应用程序内置的phonegap,我是一个很新的移动开发,这我smy第一个应用程序但是,当我尝试将一些文件(pdf,doc,jpg)下载到本地存储并打开它时,我陷入困境,通过谷歌搜索后,我试图遵循这个解决方案.

我按照示例中的确切代码,下面是我如何调用插件:

window.plugins.downloader.downloadFile(url,'/sdcard/download/', 'test.pdf', true, downloadOkCallbak, downloadErCallbak);
    window.plugins.pdfViewer.showPdf('/sdcard/download/test.pdf');
Run Code Online (Sandbox Code Playgroud)

url是我的远程文件,当我执行它时,我收到错误:"TypeError:window.plugins is undefined".任何帮助表示赞赏.

[更新]我的showPdf函数代码:

public String showPdf(String fileName) {

    File file = new File(fileName);

    if (file.exists()) {
        try {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


            //intent.setData(Uri.parse(fileName));
            this.ctx.startActivity(intent);
            return "";
        } catch (android.content.ActivityNotFoundException e) {
            System.out.println("PdfViewer: Error loading url "+fileName+":"+ e.toString());
            return e.toString();
        }            

    }else{
        return "file not found";
    }

}
Run Code Online (Sandbox Code Playgroud)

[更新2]我在Web控制台中遇到以下错误:Uncaught ReferrenceError:LocalFileSystem未在...中定义

可能是什么问题?

android cordova

7
推荐指数
1
解决办法
3万
查看次数

单击按钮后如何下载文件(Android Studio)

我最近在我的应用中创建了一个活动。现在,我希望用户在要查看指南时下载.pdf文件。我想在一个按钮上实现它。知道如何正确执行此操作吗?

下面是我的代码:

public class Exhibitor_Registration_Activity extends AppCompatActivity  {

    Button buttonDownload;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exhibitor_registration_);

        this.setTitle("Buyer Registration");

        Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        myToolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);

        final Button buttonDownload = (Button) findViewById(R.id.buttonDownload);

        buttonDownload.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                try {
                    //this is the file you want to download from the remote server
                    String path ="http://www.manilafame.com/website-assets/downloads/exhibitor-application-kit/local/201704/1-Summary-of-Participation-Details-April-2017_MN_002.pdfp";
                    //this is the name of the local file you will create
                    String targetFileName = null;
                    boolean eof = false;
                    URL u …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
1万
查看次数