如何从当前android应用程序动态下载现有apk文件?
假设我有现有的android应用程序,并且在android应用程序中还有一个功能下载按钮。当点击下载按钮时,它将下载当前的APK文件。有可能吗。如果是,那么请帮助我如何以编程方式执行此操作 如果您想在手机中预装或安装apk 请先尝试查看此文件,但需要根手机才能从系统/应用程序获取文件/如何从当前android应用程序动态下载现有apk文件?,android,Android,假设我有现有的android应用程序,并且在android应用程序中还有一个功能下载按钮。当点击下载按钮时,它将下载当前的APK文件。有可能吗。如果是,那么请帮助我如何以编程方式执行此操作 如果您想在手机中预装或安装apk 请先尝试查看此文件,但需要根手机才能从系统/应用程序获取文件/ 我认为您可以使用那里的代码将apk复制到sd卡中将apk文件放入特定的url中。通过使用文件流,您可以下载.apk文件。基本的dowload代码可以用来下载是必要的 检查以下代码: package com.he
我认为您可以使用那里的代码将apk复制到sd卡中将apk文件放入特定的url中。通过使用文件流,您可以下载.apk文件。基本的dowload代码可以用来下载是必要的 检查以下代码:
package com.helloandroid.imagedownloader;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.util.ByteArrayBuffer;
import android.util.Log;
public class ImageManager {
private final String PATH = "/data/data/com.helloandroid.imagedownloader/"; //put the downloaded file here
public void DownloadFromUrl(String imageURL, String fileName) { //this is the downloader method
try {
URL url = new URL("http://yoursite.com/" + imageURL); //you can write here any link
File file = new File(fileName);
long startTime = System.currentTimeMillis();
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
Log.d("ImageManager", "download ready in"
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
}
您想在哪里下载此apk?从谷歌游戏商店和你的网络服务器。