private void downloadFile(String fileUrl){
URL myFileUrl =null;
try {
myFileUrl= new URL(fileUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
String mPath = "sdcard/Apps_temp.apk";
FileOutputStream fos;
File f = new File(mPath);
if ( f.createNewFile() ) {
fos = new FileOutputStream(mPath);
int read;
while ( (read = is.read()) != -1) {
fos.write(read);
}
fos.close();
}
else
{
f.delete();
fos = new FileOutputStream(mPath);
int read;
while ( (read = is.read()) != -1) {
fos.write(read);
}
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "다운로드 완료", 0).show();
File apkFile = new File(Environment.getExternalStorageDirectory()+ "/Apps_temp.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType( Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(intent);
}
위와같이 파일다운로드 로직을 짜놨는데요...
위와같이 해놓으면 파일 다운로드시 화면이 모두 멈춰버리고 나중에는 에러메시지까지 뜨는데 기다린다를 누르고 기다리면
다운로드가 완료되고 파일을 설치합니다.
용량이 작은 프로그램들은 뭐 깜빡하면 지나가는데.. 용량이 1메가 이상인 애들이 문제입니다.
마켓등에서 다운로드 하는 방식같이 백그라운드로 받게 할수 있는 방법은 없는건가요???
ㅠㅠ 부탁드릴게요.ㅠㅠ 고수님들 도와주세요~~



