다운로더에 대한
는
링크 :
private class DownloadWallpaperTask extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String wallpaperURLStr = params[0];
String localPath = Integer.toString(wallpaperURLStr.hashCode());
try {
URL wallpaperURL = new URL(wallpaperURLStr);
URLConnection connection = wallpaperURL.openConnection();
//get file length
int filesize = connection.getContentLength();
if(filesize < 0) {
downloadProgressDialog.setMax(1000000);
} else {
downloadProgressDialog.setMax(filesize);
}
InputStream inputStream = new BufferedInputStream(wallpaperURL.openStream(), 10240);
String appName = getResources().getString(R.string.app_name);
OutputStream outputStream = openFileOutput(localPath, Context.MODE_PRIVATE);
byte buffer[] = new byte[1024];
int dataSize;
int loadedSize = 0;
while ((dataSize = inputStream.read(buffer)) != -1) {
loadedSize += dataSize;
publishProgress(loadedSize);
outputStream.write(buffer, 0, dataSize);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return localPath;
}
protected void onProgressUpdate(Integer... progress) {
downloadProgressDialog.setProgress(progress[0]);
}
protected void onPostExecute(String result) {
downloadProgressDialog.hide();
//open preview activity
Bundle postInfo = new Bundle();
postInfo.putString("localpath", result);
if (previewPanelIntent == null) {
previewPanelIntent = new Intent(MainActivity.this,
PreviewPanel.class);
}
previewPanelIntent.putExtras(postInfo);
startActivity(previewPanelIntent);
}
}
더 자세한 정보를 얻으려면, 내가에 사용하고 하나 개의 안드로이드 응용 프로그램의 소스 코드가 내 앱 :
Android Download Image with Progress Bar
ogcat logs .. 오류가 무엇입니까? –
인터넷 사용 허가를 위해 AndroidManifest.xml을 업데이트 했습니까? – hakiko
예. 문제는 내가 어떤 오류도받지 않는다는 것입니다. – ChoRisk