버전 업데이트 확인을 위해 응용 프로그램의 oncreate에 조건부 검사를했습니다. 응용 프로그램의 새 버전을 사용할 수있는 경우 onDestroy를 호출합니다.새 apk 파일 설치가 프로그래밍 방식으로 오류를 표시합니다.
public void onCreate(Bundle savedInstanceState) {
if(“true”.equal(CheckVersion))
{
alertbox.setMessage("Do you want to update Aplication with Latest version?");
alertbox.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
try {
onDestroy();
} catch (Exception exception) {
exception.toString();
}
}
});
alertbox.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
LaunchManifest();
}
});
alertbox.show();
}
}
/*
* In the onDestroy method I have Placed the code for downloading the New
* apk file and installation of the apk file methods as given below
*/
@Override
public void onDestroy() {
DownloadOnSDcard();
InstallApplication();
}
public void DownloadOnSDcard() {
try {
urlpath = "http://192.168.1.158/VisionEPODWebService/VisionEPOD.apk";
String ApkName = "VisionEPOD.apk";
URL url = new URL(urlpath.toString());
// Your given URL.
HttpURLConnection c = (HttpURLConnection)url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
// Connection Complete here.!
// Toast.makeText(getApplicationContext(),
// "HttpURLConnection complete.", Toast.LENGTH_SHORT).show();
String PATH = Environment.getExternalStorageDirectory() + "/download/";
File file = new File(PATH); // PATH = /mnt/sdcard/download/
if (!file.exists()) {
file.mkdirs();
}
File outputFile = new File(file, ApkName.toString());
FileOutputStream fos = new FileOutputStream(outputFile);
// Toast.makeText(getApplicationContext(), "SD Card Path: " +
// outputFile.toString(), Toast.LENGTH_SHORT).show();
InputStream is = c.getInputStream();
// Get from Server and Catch In Input Stream Object.
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1); // Write In FileOutputStream.
}
fos.close();
is.close();
// till here, it works fine - .apk is download to my sdcard in
// download file.
// So plz Check in DDMS tab and Select your Emualtor.
// Toast.makeText(getApplicationContext(),
// "Download Complete on SD Card.!", Toast.LENGTH_SHORT).show();
// download the APK to sdcard then fire the Intent.
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "Error! " + e.toString(), Toast.LENGTH_LONG)
.show();
}
}
public void InstallApplication() {
String ApkName = "VisionEPOD.apk";
String PackageName = "com.Vision.EPOD";
Uri packageURI = Uri.parse(PackageName.toString());
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, packageURI);
intent.setDataAndType(
Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/"
+ ApkName.toString())), "application/vnd.android.package-archive");
startActivity(intent);
}
문제는 설치를위한 나의 방법이 실행되었다 때이
응용 프로그램 당신이 다른 응용 프로그램을 대체하게됩니다 설치하는 응용 프로그램을 교체 경고 상자를 보여주고 있다는 점이다. 모든 이전 사용자 데이터가 저장됩니다. 그리고 확인을하고 난 그것을 응용 프로그램
의 설치를위한 또 다른 버튼을 보여 OK 버튼을 클릭하지만 설치 버튼을 클릭하면 응용 프로그램이 후 다음
를 설치 보여주는 진행률 표시 줄을 표시 할 때 버튼취소 완성 된 버튼이 설치되지 않은 메시지 애플리케이션을 받게 될 것입니다.
즉, 새 업데이트가 설치되지 않았습니다.
버전 업데이트 절차를 올바르게 구현 한 것입니까? 아무도 검토해 주실까요? 오랜 코드에 대해 죄송합니다.
logcat 출력을 살펴보십시오. 거기에도 오류 메시지가 있어야합니다. 이 메시지를 게시하면 우리는 아마도 당신을 도울 수 있습니다. – Janusz