gpt4 book ai didi

android - 更新 Android 应用(无需访问 Google Play 商店)

转载 作者:IT王子 更新时间:2023-10-28 23:42:55 34 4
gpt4 key购买 nike

我编写了该应用程序的 Beta 版。它将可以通过网络下载(我不会将其发布到 Play 市场)。当新版本发布时,是否可以在不访问 Play Market 的情况下更新此应用程序?

最佳答案

当然。但是,您需要构建一种机制,让您的应用程序调用服务器,找出是否有更新版本的应用程序,如果有,将其拉下并安装。一旦您确定确实需要拉下更新,您可以使用类似于此 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);
}

关于android - 更新 Android 应用(无需访问 Google Play 商店),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213211/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com