1
파일 다운로드에 문제가 있습니다.Android 휴대 전화에서 파일을 다운로드 할 수 없습니다. - Android ..?
에뮬레이터에서는 파일을 다운로드 할 수 있습니다 만, 전화로는 동작하지 않습니다. 나는 인터넷을위한 허가를 정의하고 SD 카드를 쓴다.
서버에 하나의 doc 파일이 있고 사용자가 다운로드를 클릭하면됩니다. 파일을 다운로드합니다. 이 은 에뮬레이터에서 잘 작동하지만 전화로는 작동하지 않습니다.
Plz 해결책 찾기에 도움이됩니다.
감사합니다.
* 편집 *
public void downloadFile(String _url, String fileName) {
File PATH = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
try {
PATH.mkdirs();
URL url = new URL(_url); // you can write here any link
File file = new File(PATH, fileName);
long startTime = System.currentTimeMillis();
Log.d("Manager", "download begining");
Log.d("DownloadManager", "download url:" + url);
Log.d("DownloadManager", "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager",
"download ready in"
+ ((System.currentTimeMillis() - startTime)/1000)
+ " sec");
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
logcat에 오류가 있습니까? 어쩌면 코드 조각일까요? –
일부 정보를 붙여 넣으십시오.이 정보는 도움이되지 않습니다. – oriolpons
Nop, logcat은 오류를주지 않습니다. –