2013年9月7日星期六

android download the file, how to do after downloading thefollowing program is executed ?


/**  
     * 将一个InputStream里面的数据写入到SD卡中  
     * @param path  
     * @param fileName  
     * @param input  
     * @return  
     */  
    public File write2SDFromInput(String path,String fileName,InputStream input){
        File file = null;  
        OutputStream output = null;  
        try {  
            createSDDir(path);  
            String str = path + fileName;
            file = createSDFile(path + fileName);
            output = new FileOutputStream(file);  
            byte[] buffer = new byte[FILESIZE];  
            while((input.read(buffer)) != -1){  
                output.write(buffer);  
            }  
            output.flush();  
        }   
        catch (Exception e) {  
            e.printStackTrace();  
        }  
        finally{  
            try {  
                output.close();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
        return file;  
    }


How to download code added in blocking , so he downloaded the following program is executed again . Please help us to see
------ Solution ----------------------------------- ---------
blocked ? UI will be blocked for more than 5s ANR, only through the handler and the thread with the realization , but there must be blocked during a prompt window or what kind of
------ Solution ------- -------------------------------------
installation and download into the same thread on the line , java that level triggered
------ Solution ---------------------------------- ----------
reference:
Android shows online photo
---- - reference ---------------------------------------
then how do things right , like C # fetch data from the com port when the direct use cretefile took a blocking function parameters . This has not been engaged in do not know where to start the

actually wanted to achieve , download files function call , wait until then downloaded from the download function which calls down the implementation . . .
------ reference --------------------------------------- < br> no way , I downloaded pictures ----- > to display pictures is written in a function , it's useless multithreading , that this does not belong to a single-threaded Mody
code below: download and display the time in a click inside

//ListView单击事件
list_view_presentation.setOnItemClickListener(new OnItemClickListener(){
.
.
.
.
.
.
//下载函数downFile
int result = downloader.downFile("http://172.16.0.78:8082/upload/download/"+presentationName+"/"+presentationName+"_1.jpg", "download/"+presentationName+"/", presentationName+"_1.jpg");

//接下来就是现实图片的方法了
sum =1;
setHtml(imagePath+presentationName+"/"+presentationName+"_1.jpg");
imageName = presentationName;
webview.loadDataWithBaseURL("about:blank", html, "text/html", "utf-8",null);
webview.setVisibility(View.VISIBLE);
}});

}

------ reference ------------------------------------- -
I still can not use this method of online access to pictures , because a lot of people visit , and if my next visit to the local server only once . Later to see local pictures. . . Hey ~ ~ ~ ~
------ reference ----------------------------------- ----
plus a cycle of death
while (true) {
if (" determine if the download finished " ) {
break;
}
}
After downloading the statement to run ....

没有评论:

发表评论