1. <i id='RaUUr'><tr id='RaUUr'><dt id='RaUUr'><q id='RaUUr'><span id='RaUUr'><b id='RaUUr'><form id='RaUUr'><ins id='RaUUr'></ins><ul id='RaUUr'></ul><sub id='RaUUr'></sub></form><legend id='RaUUr'></legend><bdo id='RaUUr'><pre id='RaUUr'><center id='RaUUr'></center></pre></bdo></b><th id='RaUUr'></th></span></q></dt></tr></i><div id='RaUUr'><tfoot id='RaUUr'></tfoot><dl id='RaUUr'><fieldset id='RaUUr'></fieldset></dl></div>

    <small id='RaUUr'></small><noframes id='RaUUr'>

    <legend id='RaUUr'><style id='RaUUr'><dir id='RaUUr'><q id='RaUUr'></q></dir></style></legend>

  2. <tfoot id='RaUUr'></tfoot>
      <bdo id='RaUUr'></bdo><ul id='RaUUr'></ul>

      用安卓下载文件

      时间:2024-04-14
        • <bdo id='zfmkH'></bdo><ul id='zfmkH'></ul>

          1. <small id='zfmkH'></small><noframes id='zfmkH'>

            <i id='zfmkH'><tr id='zfmkH'><dt id='zfmkH'><q id='zfmkH'><span id='zfmkH'><b id='zfmkH'><form id='zfmkH'><ins id='zfmkH'></ins><ul id='zfmkH'></ul><sub id='zfmkH'></sub></form><legend id='zfmkH'></legend><bdo id='zfmkH'><pre id='zfmkH'><center id='zfmkH'></center></pre></bdo></b><th id='zfmkH'></th></span></q></dt></tr></i><div id='zfmkH'><tfoot id='zfmkH'></tfoot><dl id='zfmkH'><fieldset id='zfmkH'></fieldset></dl></div>
                <tbody id='zfmkH'></tbody>
              <tfoot id='zfmkH'></tfoot>
              1. <legend id='zfmkH'><style id='zfmkH'><dir id='zfmkH'><q id='zfmkH'></q></dir></style></legend>
                本文介绍了用安卓下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试将文件从网络保存到我的 Android 设备,但我不知道该怎么做.URL 地址会打开一个空白页面和一个弹出下载框,其中包含我要下载的文件,以便我可以选择保存位置.

                I am trying to save a file from the web to my Android device, but I do not know how to do it. The URL address opens a blank page and a popup download box with the file that I want to download so I can choose where to save it.

                我的问题是我不知道如何管理该框以下载文件.我不想下载该页面上显示的内容,因为该页面是空白的.所以我不能使用这个代码:

                My problem is that I do not know how to manage that box in order to download the file. It is not like I want to download something that is shown on that page because the page is blank. So I cannot use this code :

                         Context context = thisClass.this;
                         Drawable image = ImageOperations(context,
                          "http://android.okhelp.cz/images/adictionary/ad_4.png"
                          ,"image.jpg");
                         ImageView imgView;
                         imgView = (ImageView)findViewById(R.id.idImageView);
                         imgView.setImageDrawable(image);
                
                private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
                    try {
                        InputStream is = (InputStream) this.fetch(url);
                        Drawable d = Drawable.createFromStream(is, "src");
                        return d;
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        return null;
                    } catch (IOException e) {
                        e.printStackTrace();
                        return null;
                    }
                }
                
                public Object fetch(String address) throws MalformedURLException,IOException {
                    URL url = new URL(address);
                    Object content = url.getContent();
                    return content;
                }
                

                如果有人能指出从哪里开始寻找或给我一个解决方案,我将不胜感激.

                I would be grateful if someone could point me where to start looking or gave me a solution.

                推荐答案

                我解决了!

                           File card2= Environment.getExternalStorageDirectory();
                           File dir2= new File (card2.getAbsolutePath()+"/MyFiles");
                            dir2.mkdirs();
                           new DefaultHttpClient().execute(new HttpGet(your_url_here-this_is_a_string)).getEntity().writeTo(
                            new FileOutputStream(new File(dir2,your_file_on_sdcard-this_is_string)));
                

                这也被 try/catch 包围.并记得在地址前插入协议,否则将不起作用!希望对您有所帮助!

                This is also surrounded by try/catch. And remember to insert the protocol before the address or it won't work! Hope it helps!

                这篇关于用安卓下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在弹出窗口中显示地图 v2 不在 android 中显示? 下一篇:在弹出的android中打开pdf

                相关文章

                1. <legend id='XLOC6'><style id='XLOC6'><dir id='XLOC6'><q id='XLOC6'></q></dir></style></legend>

                  <small id='XLOC6'></small><noframes id='XLOC6'>

                  <tfoot id='XLOC6'></tfoot>
                  <i id='XLOC6'><tr id='XLOC6'><dt id='XLOC6'><q id='XLOC6'><span id='XLOC6'><b id='XLOC6'><form id='XLOC6'><ins id='XLOC6'></ins><ul id='XLOC6'></ul><sub id='XLOC6'></sub></form><legend id='XLOC6'></legend><bdo id='XLOC6'><pre id='XLOC6'><center id='XLOC6'></center></pre></bdo></b><th id='XLOC6'></th></span></q></dt></tr></i><div id='XLOC6'><tfoot id='XLOC6'></tfoot><dl id='XLOC6'><fieldset id='XLOC6'></fieldset></dl></div>

                  • <bdo id='XLOC6'></bdo><ul id='XLOC6'></ul>