String File_Name = "";
String File_extend = "";
String fileURL = "http://웹서버에 올려진 URL주소/"; // URL
String Save_Path = "/data/data/kr.appsol.util.calc.formcalc/themes";
DownloadThread dThread;
ProgressDialog downDialog = null;
private void skinDownload(String no){
String skinId = db.select_SkinId(no);
// skinId 는
// kr.appsol.util.calc.formcalc.skin.whitesilver
//이라는 어플2의 파일명이지 패키지명입니다.
File_Name = skinId + ".apk";
File_extend = "apk";
File dir = new File(Save_Path);
// 폴더가 존재하지 않을 경우 폴더를 만듦
if (!dir.exists()) {
dir.mkdir();
}
// 다운로드 폴더에 동일한 파일명이 존재하는지 확인해서
// 없으면 다운받고 있으면 해당 파일 실행시킴.
if (new File(Save_Path + "/" + File_Name).exists() == false) {
//loadingBar.setVisibility(View.VISIBLE);
downDialog = ProgressDialog.show(Activity_SkinList.this, "", getString(R.string.setting_skin_downloading));
downDialog.show();
dThread = new DownloadThread(fileURL + "/" + File_Name,
Save_Path + "/" + File_Name);
dThread.start();
} else {
showDownloadFile();
}
}
class DownloadThread extends Thread {
String ServerUrl;
String LocalPath;
DownloadThread(String serverPath, String localPath) {
ServerUrl = serverPath;
LocalPath = localPath;
}
@Override
public void run() {
URL imgurl;
int Read;
try {
imgurl = new URL(ServerUrl);
HttpURLConnection conn = (HttpURLConnection) imgurl
.openConnection();
int len = conn.getContentLength();
byte[] tmpByte = new byte[len];
InputStream is = conn.getInputStream();
File file = new File(LocalPath);
FileOutputStream fos = new FileOutputStream(file);
for (;;) {
Read = is.read(tmpByte);
if (Read <= 0) {
break;
}
fos.write(tmpByte, 0, Read);
}
is.close();
fos.close();
conn.disconnect();
} catch (MalformedURLException e) {
Log.e("ERROR1", e.getMessage());
} catch (IOException e) {
Log.e("ERROR2", e.getMessage());
e.printStackTrace();
}
mAfterDown.sendEmptyMessage(0);
}
}
Handler mAfterDown = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
//loadingBar.setVisibility(View.GONE);
downDialog.dismiss();
// 파일 다운로드 종료 후 다운받은 파일을 실행시킨다.
showDownloadFile();
}
};
private void showDownloadFile() {
File apkFile = new File(Save_Path + "/" + File_Name);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
startActivity(intent);
}
안녕하세요?
어제 밤부터 이문제로 고민하였지만.. 결국엔 해결 하지 못하고 질문 드립니다.
일단.. 어플1 에서 어플2.apk를 다운 받아 실행 시키는 건데요..
어플2.apk를 다운 받는것 까진 됐는데.. 실행 부분에서 자꾸
구문분석오류
패키지 파일을 분할하는 중에 문제가 발생하였습니다.
라는 팝업이 나오네요..
어플 2는 어플1에서 참조할 리소스가 있는 스킨 어플 입니다..
소스는 위와 같구요..
skinDownload(String); 로 시작합니다. 파일명은 db에서 불러오구요..
이상한건.. 그냥 sub케이블 꼿아서 기기에 넣고 파일관리자로 실행시키면 문제없이 되는데
어플1에서 어플2.apk 를 다운받아서 실행시키면 저런 에러가 나네요..
어플1에서 다운 받은걸 다시 sd카드에 옴겨서 파일관리자로 실행 시켰을때도 됩니다..
어플2.apk는 문제가 없는거죠??
다른 개발자 분들의 답변을 기다립니다 ...