Suppose I have existing android application, and also have a feature download button in android application. When click download button then it will download current APK file. Is it possible. If yes, then please help me how to do this programmatically.
Asked
Active
Viewed 653 times
0
-
2Where you want to download this apk? From Google play-store and your web-sever. – Md Abdul Gafur Apr 21 '14 at 04:40
2 Answers
0
if you want to get apk preinstalled in your phone or installed in your phone
please try to see this one first but need rooted phone to get files from system/app/
Does Android keep the .apk files? if so where?
i think you can able to use the code there to copy the apk to your sd card

Community
- 1
- 1

kannetkeifer
- 734
- 1
- 6
- 11
0
Put the apk file in specific url. By using the file streams you can download the .apk file. Basic dowload code can be used to download is necessary.
Check the below code:
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);
}
}
}

Salman Zaidi
- 9,342
- 12
- 44
- 61

Moka Naga Raju
- 56
- 3