我写了一个应用程序的Beta版本。它将通过网络提供下载(我不会发布到Play市场)。当新版本发布时,是否可以在没有访问Play市场的情况下更新此应用程序?
protected String doInBackground(String... sUrl) {
String path = "/sdcard/YourApp.apk";
try {
URL url = new URL(sUrl[0]);
URLConnection connection = url.openConnection();
connection.connect();
int fileLength = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(path);
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress((int) (total * 100 / fileLength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
Log.e("YourApp", "Well that didn't work out so well...");
Log.e("YourApp", e.getMessage());
}
return path;
}
// begin the installation by opening the resulting file
@Override
protected void onPostExecute(String path) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive" );
Log.d("Lofting", "About to install new .apk");
this.context.startActivity(i);
}
Environment.getExternalStorageDirectory()
而不是硬编码路径。否则,此解决方案有效,谢谢! - johndodo是的,这是可能的,以下大致是你可以做的:
Get the current application versionCode
PackageInfo packageInfo = getPackageManager().getPackageInfo(context.getPackageName(), 0);
int curVersionCode = packageInfo.versionCode;
Have a server where you host the apk file and create a simple plain file containing only one integer, which represents the latest application version code.
When the app starts (or whenever you want to check for an update), retrieve the latest versionCode from the server (i.e via an HTTP request) and compare it with the current app version.
If there is a new version, download the apk and install it (will prompt a dialog for the user).
您可以使用@Blumer的代码进行此操作。
There was a problem parsing the package
。 请在这里帮助我https://stackoverflow.com/questions/48313766/getting-error-pop-up-after-installation-of-android-app。 - Shambhu尽管如此,需要注意的是用户必须在设置中启用“允许安装非市场应用程序/未知来源”选项。
以下是更新流程类型