我想通过单击列表视图项目
来下载文件(MP4)请就此提供指导!
答案 0 :(得分:0)
onItemClickListener
编写代码下载任何文件,
int count;
try {
URL url = new URL("YOUR_URL");
URLConnection conection = url.openConnection();
conection.connect();
int lenghtOfFile = conection.getContentLength();
InputStream input = new BufferedInputStream(url.openStream(), 8192);
OutputStream output = new FileOutputStream("DOWNLOAD_LOCATION");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}
注意:您必须在AsyncTask
中编写此代码,并且android.permission.INTERNET
是必需的。