假设我有现有的android应用程序,并且在android应用程序中也有一个功能下载按钮。单击“下载”按钮后,它将下载当前的APK文件。有可能。如果是,那么请帮助我如何通过编程完成这一工作。
发布于 2014-04-20 20:55:59
如果您想在您的手机中预装apk或安装在您的手机中
请先看看这个,但是需要有根的手机才能从system/app/ /获取文件。
Does Android keep the .apk files? if so where?
我认为您可以使用那里的代码将apk复制到您的sd卡上。
发布于 2014-04-20 21:01:42
将apk文件放入特定的url中。通过使用文件流,您可以下载.apk文件。基本的下载代码可以用来下载是必要的。
检查以下代码:
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);
}
}
}
https://stackoverflow.com/questions/23190860
复制相似问题