我写了一个应用程序的Beta版本.它可以通过网络下载(我不会将其发布到Play Market).在新版本发布时,是否可以在没有Play Market的情况下更新此应用程序?
Blu*_*mer 80
绝对.但是,您需要构建一个机制,让您的应用程序调用服务器的主页,查看是否有更新版本的应用程序,如果有,请将其下拉并安装.一旦确定需要下拉更新,就可以使用与此AsyncTask类似的内容:
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);
}
Run Code Online (Sandbox Code Playgroud)
iTe*_*ech 15
是的,这是可能的,这里大致是你可以做的:
获取当前的应用程序版本代码
PackageInfo packageInfo = getPackageManager().getPackageInfo(context.getPackageName(), 0);
int curVersionCode = packageInfo.versionCode;
Run Code Online (Sandbox Code Playgroud)有一个托管apk文件的服务器,并创建一个只包含一个整数的简单普通文件,该文件代表最新的应用程序版本代码.
当应用程序启动时(或者每当您想要检查更新时),从服务器检索最新的versionCode(即通过HTTP请求)并将其与当前的应用程序版本进行比较.
如果有新版本,请下载apk并安装它(将为用户提示对话框).
您可以使用@Blumer的代码.
以下是更新流程的类型
| 归档时间: |
|
| 查看次数: |
78346 次 |
| 最近记录: |