Hi folks,
If you are planning to develop android application which is responsible to download .apk file from server(not market app,Enterprise distribution) and then install it on to the device this post will help you
so here is the choice.
1. Download Manager: this can be done using the Download Manager available from 2.3.3 your newely downloaded file goes in Downloads application as shown below,you can install your newly download .apk by clicking on it .
Android system just ask for permission to install your .apk with the help of Package Installer . This seems that after downloading their is no controls of your application to install it rather than going to downloads and manually install the .apk .I am not explaing the the code for Download Manager coz this post is all about "How to download .apk from server and install it programatically" :-).
So here is the 2nd way
2.
a. First download .apk file using simple http connection and store it on external storage area.
If you are planning to develop android application which is responsible to download .apk file from server(not market app,Enterprise distribution) and then install it on to the device this post will help you
so here is the choice.
1. Download Manager: this can be done using the Download Manager available from 2.3.3 your newely downloaded file goes in Downloads application as shown below,you can install your newly download .apk by clicking on it .
Android system just ask for permission to install your .apk with the help of Package Installer . This seems that after downloading their is no controls of your application to install it rather than going to downloads and manually install the .apk .I am not explaing the the code for Download Manager coz this post is all about "How to download .apk from server and install it programatically" :-).
So here is the 2nd way
2.
a. First download .apk file using simple http connection and store it on external storage area.
private void downloadapk(){
try {
URL url = new URL("http://www.efimoto.com/nilesh/HelloWorldProject.apk");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "filename.apk");
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
this.checkUnknownSourceEnability();
this.initiateInstallation();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
b. Now instantiate installing process.
private void installApk(){
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File("/sdcard/filename.apk"));
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);
}
c. Give uses-permission in application menifest file.
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.INTERNET"/>
d. Ensure that your "Unknown source " check box must enable.
I have been created simple UI for this having a button when button clicked it downloads apk after that installation process appears . If unknown source is disable you must got "Install blocked"
That's all, you are successfully downloaded and installed your .apk from server.
feel free to query @: bpsingh216@gmail.com
enjoy coding :-)
This site is truly helpful.. Thanks To Mr.BpSingh for creating such informative and helpful site for beginners in android app development.. Got a lot to learn!!
ReplyDeletethis is very good blog....really awesome content available here
ReplyDeleteplease provide some material regarding task killer application
ReplyDeleteINSTALL_PACKAGES permission is only granted to system apps. How did you manage to do it? My IDE (Android Studio) won't even compile the application.
ReplyDeletepress project-> Clean button and than code will be run fine
DeleteWhy i am getting exception message " Parse error . There is a problem parsing the package"
ReplyDeletecheckUnknownSourceEnability() where is this method ?
ReplyDeleteplease provide this method
Is it possible to install application without apk being downloaded on the phone just like what googleplay playstore does...
ReplyDeleteThank you
When i try to run this i am getting my app has stopped.I am new to android. can you help me with this please
ReplyDeleteHi man if you still Alive, i want to ask you ,where should i put these code (in OnCreate methode, or what ??), at least explain where to put them man .
ReplyDeletehope you answer or any one passes by
ReplyDeletei got this exception at the time of installation;
android.os.FileUriExposedException: file:///storage/emulated/0/test.apk exposed beyond app through Intent.getData()
Can any one helm me.
ReplyDeleteIt seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job. Keep it up…
ReplyDeleteUpgrade your career Learn Oracle Training from industry experts gets complete hands on Training, Interview preparation, and Job Assistance at Softgen Infotech.
From your blog I have understood that which will be better for me and which is easy to use. Really, I have liked your brilliant blog. I will comThis is great helping material for every one visitor. You have done a great responsible person. i want to say thanks owner of this blog.
ReplyDeletedevops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery
Is it possible to install application without apk being downloaded on the phone just like what googleplay playstore does...
ReplyDeleteweb designing training in chennai
web designing training in omr
digital marketing training in chennai
digital marketing training in omr
rpa training in chennai
rpa training in omr
tally training in chennai
tally training in omr
I like your such a valuable post for us. It is one of the excellent articles for this topic. It is very helpful for me and keeps doing...
ReplyDeleteoracle training in chennai
oracle training in tambaram
oracle dba training in chennai
oracle dba training in tambaram
ccna training in chennai
ccna training in tambaram
seo training in chennai
seo training in tambaram
I like your such a valuable post for us. It is one of the excellent articles for this topic. It is very helpful for me and keeps doing...
ReplyDeleteAWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
It¦s truly a nice and helpful piece of info. I am satisfied that you simply shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
ReplyDeleteangular js training in chennai
angular js training in velachery
full stack training in chennai
full stack training in velachery
php training in chennai
php training in velachery
photoshop training in chennai
photoshop training in velachery
This is beyond amazing. Keep posting like this. Very interesting.
ReplyDeletejava training in chennai
java training in annanagar
aws training in chennai
aws training in annanagar
python training in chennai
python training in annanagar
selenium training in chennai
selenium training in annanagar
nft nasıl alınır
ReplyDeleteen son çıkan perde modelleri
lisans satın al
özel ambulans
en son çıkan perde modelleri
yurtdışı kargo
uc satın al
minecraft premium