마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

다운로드 apk 실행 관련

0 추천
 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는 문제가 없는거죠??

 

다른 개발자 분들의 답변을 기다립니다 ...

Ripple (810 포인트) 님이 2014년 2월 20일 질문

3개의 답변

0 추천

혹시 인텐트에 플래그를 설정하는 부분이 필요한지 모르겠네요. 한 번 테스트해보세요.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

 

여기를 참고하세요.

http://stackoverflow.com/a/11856143

 

 

 

방귀과장 (18,940 포인트) 님이 2014년 2월 20일 답변
0 추천
도움이 되진 않으시겠지만, 저같은 경우는 해당현상이 디바이스의 버전과 apk에서 요구하는 minrequestVersion의 차이때문에 발생한적이 있습니다. 참고하시길..
주드로이드 (340 포인트) 님이 2014년 2월 20일 답변
0 추천
     if (Read <= 0) {
      break;
     }
위 코드에 문제가 있습니다. 0보다 작을 때 빠져나가야 합니다.

이 외에는 아래 사항을 확인해보세요.

1. apk파일이 올바르게 받아졌는지 확인합니다. (sha1 등)
2. adb 명령을 이용해 수동으로 해당 apk를 설치해서 오류가 없는지 확인합니다.

익명사용자 님이 2014년 2월 20일 답변
...