If you want to install a custom app dynamically from your app, then it is quite simple. For this, you need to place APK on a downloadable URL, so that it can be downloaded directly. Then you can access app url and install. Since you want to install app from your app, then you need to download the APK first and then install your custom app. It thus need to do in background.
Here is the code.
I installed custom app on launch of my app i.e. MainActivity
//Download APK and then Install Custom App
InstallApp customApp= new InstallApp();
customApp.setContext(myContext);
customApp.execute("http://APK-URL/AppName.apk");
Following is the code to download the apk in background then install app.
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class InstallApp extends AsyncTask<String,Void,Void> {
private Context context;
private final String TAG = "InstallApp";
public void setContext(Context context){
this.context = context;
}
@Override
protected Void doInBackground(String... apk_url) {
try {
//URL of the APK, to download
URL download_url = new URL(apk_url[0]);
HttpURLConnection c = (HttpURLConnection) download_url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
//Download APK to download folder. Save APK file with CustomApp.apk
File file = new File(Environment.getExternalStorageDirectory() + "/download/");
file.mkdirs();
File downloadFile= new File(file, "CustomApp.apk");
if(downloadFile.exists()){
downloadFile.delete();
}
FileOutputStream fos = new FileOutputStream(downloadFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int lenght = 0;
while ((lenght = is.read(buffer)) != -1) {
fos.write(buffer, 0, lenght);
}
fos.close();
is.close();
//Install App Intent
Intent install_intent = new Intent(Intent.ACTION_VIEW);
install_intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "CustomApp.apk")), "application/vnd.android.package-archive");
install_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(install_intent);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
return null;
}
}
Similarly, if you want to uninstall app from another app, then here is code:
//Uninstall app
Similarly, if you want to uninstall app from another app, then here is code:
//Uninstall app
Uri packageUri = Uri.parse("package:"+"name of app package");
//OS >= 14 supports ACTION_UNINSTALL_PACKAGE
//OS < 14 ACTION_DELETE
//Therefore, for all OS, use the following.
//OS < 14 ACTION_DELETE
//Therefore, for all OS, use the following.
Intent appUninstall= new Intent( (Build.VERSION.SDK_INT >= 14)?Intent.ACTION_UNINSTALL_PACKAGE: Intent.ACTION_DELETE, packageUri);
startActivity(appUninstall);
Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
ReplyDeleteselenium Training in Chennai
amazon web services Training in Chennai
rpa Training in Chennai
Resources like the one you mentioned here will be very useful to me ! I will post a link to this page on my blog. I am sure my visitors will find that very useful
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in OMR
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
ReplyDeletejava training in tambaram | java training in velachery
java training in omr | oracle training in chennai
java training in annanagar | java training in chennai
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
ReplyDeletepython training in pune
python online training
python training in OMR
I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
ReplyDeleteBlueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
ReplyDeleteangularjs Training in chennai
angularjs-Training in pune
angularjs-Training in chennai
angularjs Training in chennai
angularjs-Training in tambaram
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check Angularjs Training in Chennai | Angular 2 Training in Chennai Get trained by an expert who will enrich you with the latest updates.
ReplyDeleteAngularjs Training
Angularjs Training near me
Angularjs course in Chennai
Best Article ever....
ReplyDeleteAfter reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience. Thank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in
ReplyDeletedevops online training
aws online training
data science with python online training
data science online training
rpa online training
Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. I want to say thanks for great sharing.
ReplyDeleteMicrosoft Azure online training
Selenium online training
Java online training
Python online training
uipath online training
very nice post thanks for sharing the valuable information with us
ReplyDeleteAngularJS Training in Chennai | AngularJS Training in Anna Nagar | AngularJS Training in OMR | AngularJS Training in Porur | AngularJS Training in Tambaram | AngularJS Training in Velachery
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.share more details.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
Nice Post! Thank you for sharing very good post, it was so Nice to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteAWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery
This blog give to me valuable technical knowledge ... I shall share few innovations that Android is getting ready for its users in 2020:
ReplyDeleteAndroid Training in Chennai
Android Online Training in Chennai
Android Training in Bangalore
Android Training in Hyderabad
Android Training in Coimbatore
Android Training
Android Online Training
Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
ReplyDeleteAngular js Training in Chennai
Angular js Training in Velachery
Angular js Training in Tambaram
Angular js Training in Porur
Angular js Training in Omr
Angular js Training in Annanagar
This blog is really amazing to read. The content is very precise. Thanks for sharing it across. The content is very useful and informative. I can understand very easily
ReplyDeleteSelenium Training in Chennai
Selenium Training in Velachery
Selenium Training in Tambaram
Selenium Training in Porur
Selenium Training in Omr
Selenium Training in Annanagar
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us.
ReplyDeleteamazon web services aws training in chennai
microsoft azure course in chennai
workday course in chennai
android course in chennai
ios course in chennai
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletetally training in chennai
hadoop training in chennai
sap training in chennai
oracle training in chennai
angular js training in chennai
Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
Spoken english classes in chennai | Communication training
Title:
ReplyDeleteStudy Oracle Course in Chennai | Infycle Technologies
Description:
Did you want to set your career towards Oracle? Then Infycle is with you to make this into reality. Infycle Technologies gives the combined and best Oracle course in Chennai, which offers various stages of Oracle such as Oracle PL/SQL, Oracle DBA, etc., along with 100% hands-on training guided by experienced trainers in the field. Once after the training, the interviews will be arranged in the MNC's and firms for the placement. To have the Oracle with the best future, call 7502633633 and make this happen for your happy life.
Best training in Chennai
Title:
ReplyDeleteTop AWS Course in Chennai | Infycle Technologies
Description:
Learn Amazon Web Services for excellent job opportunities from Infycle Technologies, the best AWS training center in Chennai. Infycle Technologies gives the most trustworthy AWS course in Chennai, with full hands-on practical training from professional trainers in the field. Along with that, the placement interviews will be arranged for the candidates, so that, they can meet the job interviews without missing them. To transform your career to the next level, call 7502633633 to Infycle Technologies and grab a free demo to know more
best training institute in chennai
Grab Data Science Certification in Chennai for skyrocketing your career with Infycle Technologies, the best Software Training & Placement institutes in and around Chennai. In addition to the Certification, Infycle also gives the best placement training for personality tests, interview preparation, and mock interviews for leveling up the candidate's grades to a professional level.
ReplyDeleteInfycle Technologies, the top software training institute and placement center in Chennai offers the Best Digital Marketing course in Chennai for freshers, students, and tech professionals at the best offers. In addition to Digital Marketing, other in-demand courses such as DevOps, Data Science, Python, Selenium, Big Data, Java, Power BI, Oracle will also be trained with 100% practical classes. After the completion of training, the trainees will be sent for placement interviews in the top MNC's. Call 7504633633 to get more info and a free demo.
ReplyDeleteInfycle Technologies offers the best Python training in Chennai for tech professionals and freshers with New year offers. In addition to the Python Training Course, Infycle also offers other technical courses such as Data Science, Oracle, Java, Power BI, Digital Marketing, Big Data, etc., which will be trained with complete practical classes. Dial 7504633633 to get more info and a free demo.
ReplyDelete