0
Google Play 스토어 밖에서 내 Android에 대한 업데이트를 다운로드하여 설치하려고합니다. 가이드로 사용 (http://simpledeveloper.com/how-to-update-android-apk-outside-the-playstore/) 내 Google 드라이브에서 내 앱 (업데이트가 있음) 용 apk 파일을 다운로드하는 코드를 앱에 삽입했습니다.Android 파싱 패키지 파싱 - 부분 다운로드
앱은 파일의 일부만 다운로드합니다 (어쩌면 처음 14KB ~ 100KB).
내가 뭘 잘못하고 있니?
public class ApkUpdateTask extends AsyncTask <String,Void,Void>{
private Context context;
public void setContext(Context contextf){
context = contextf;
}
@Override
protected Void doInBackground(String... arg0) {
try {
URL url = new URL(arg0[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
String PATH = "/storage/emulated/0/Download/";
//String PATH = Environment.getExternalStorageDirectory().getPath();
File file = new File(PATH);
//file.mkdirs();
File outputFile = new File(file, "sonandso.apk");
if(outputFile.exists()){
outputFile.delete();
}
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
Intent intent = new Intent(Intent.ACTION_VIEW);
//intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath())), "blahblah.apk");
intent.setDataAndType(Uri.fromFile(new File("/storage/emulated/0/Download/")), "blahblah.apk");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
context.startActivity(intent);
} catch (Exception e) {
Log.e("UpdateAPP", "Update error! " + e.getMessage());
}
return null;
}
}
참고 : 나는 모두 서명하고 서명 된 APK를 만든
-
여기 내 코드입니다. 둘 다 전체 앱을 다운로드하지 못합니다.
- apk 레벨이 api 수준으로 장치의 동일한 API 수준으로 설정되어 있습니다 (gradle 빌드 파일에서 Android Studio를 사용 중입니다). 안드로이드 버전은 5.1.1입니다 (프로젝트 때문에 야합니다).
- 주 파편에서 위에 나열된 코드 (별도의 클래스 파일에 넣음)를 호출합니다. 이것은 주요 활동 자체에서 호출해야합니까 ??
- 외부 저장 장치 메모리에 쓰려고하는데 외부 SD 카드가 아닙니다. 이것이 문제가 될 수 있습니까? 그렇다면 어떻게 내부 스토리지 메모리에 기록 할 수 있습니까?
- "Environment.getExternalStorageDirectory(). getPath()"를 사용하여 경로를 시도했지만 그 중 하나가 작동하지 않았습니다. 질문에 대해서는 # 4를 참조하십시오.