2013-09-24 4 views
2

다음 프로그램을 사용하여 apk를 다운로드하고 설치합니다. 어떻게 성공적으로 설치 후 apk를 sdcard에서 제거 할 수 있습니까? 내가 시도한 것은 :설치 후 .apk를 삭제하는 방법

File file = new File("/sdcard/filename.apk"); 
boolean deleted = file.delete(); 

그러나 설치하기 전에 파일을 삭제합니다. 설치가 완료되면

protected Boolean doInBackground(String... arg0) { 
    try { 
    URL url = new URL(weburl +"username="+usename+"&password="+usepass +"&apk="+apk); 
    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 
    urlConnection.setRequestMethod("GET"); 
    urlConnection.setDoOutput(true); 
    urlConnection.connect(); 

    File sdcard = Environment.getExternalStorageDirectory(); 
    File file = new File(sdcard, "filename.apk"); 

    FileOutputStream fileOutput = new FileOutputStream(file); 
    InputStream inputStream = urlConnection.getInputStream(); 

    byte[] buffer = new byte[1024]; 
    int bufferLength = 0; 

    while ((bufferLength = inputStream.read(buffer)) > 0) { 
    fileOutput.write(buffer, 0, bufferLength); 
    } 
    fileOutput.close(); 
    // this.checkUnknownSourceEnability(); 
    // this.initiateInstallation(); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    Uri uri = Uri.fromFile(new File("/sdcard/filename.apk")); 
    intent.setDataAndType(uri, "application/vnd.android.package-archive"); 
    startActivity(intent); 

    } catch (MalformedURLException e) { 
    e.printStackTrace(); 
    } catch (IOException e) { 
    e.printStackTrace(); 
    } 
    return null; 
} 

private void installApk(){ 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    Uri uri = Uri.fromFile(new File("/sdcard/filename.apk")); 
    intent.setDataAndType(uri, "application/vnd.android.package-archive"); 
    startActivity(intent); 
} 
+0

중복 가능성 [설치가 완료되면 알 방법] (http://stackoverflow.com/questions/5176645/how-to-find-out를 참조하십시오 - 설치가 완료되면 – flx

+1

[설치 후 응용 프로그램 (\ *. apk) 삭제 가능] (http://stackoverflow.com/questions/15984546/delete-an-application-apk-after) -설치) –

답변

관련 문제