, it was my own .
好吧安裝解析包時出現問題,這是我自己的錯誤。 Sorry for up and about my fine code.
對不起,任何人掃描我的完美工作代碼感到沮喪。
The was me, to the app I ran from over USB.
原因是我,試圖更新通過USB直接從 運行的應用程序。 it's been on "" mode, it the parse error on the newly apk file (I'm still not sure why).
盡管它一直在“發布”模式下運行,但它會在新下載的apk文件上引發解析錯誤(我仍然不確定為什么)。
So, I just a apk with (lower) ;
因此安裝解析包時出現問題,我剛剛生成了帶有正確(較低)版本控制的簽名apk; copy it into the phone and then .
將其復制到手機中,然后安裝。 Only then, the app can and run the newer apk file.
只有這樣,應用程序才能正確下載并運行更新版本的apk文件。 as .
按預期更新自己。
Let this be an case for did the same thing as me.
讓這作為一個示例案例,說明有人做過與我相同的事情。 Use apk when for a .
測試手動更新功能時,請使用生成的apk。
, I want to share my code.
最后,我想分享我的代碼。 I it from FTP to via .
我將其從FTP更改為通過直接下載。 Both work fine (the code in the and this).
兩種版本都可以正常工作(問題和此代碼)。 So feel free to the one suits your job.
因此,隨時選擇適合您工作的一種。
class Update implements Runnable {
@Override
public void run() {
try {
URL url = new URL("mysite.com/app-release.apk");
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();

String PATH = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS).getAbsolutePath();
File file = new File(PATH);
File outputFile = new File(file, "app-release.apk");
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}

fos.close();
is.close();
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(outputFile), "application/vnd.android.package-archive")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(promptInstall);
} catch (Exception ex) {
//catch exception
}
}
}