18

I was wondering if it was possible to have an android app which is already installed go and download another app and install it? I figure there could be security problems with this, but is it possible for the Android OS to do this?

Anton
  • 12,285
  • 20
  • 64
  • 84
  • I think one thing many of these answers failed to mention is ***system apps*** and their special ability to have the [`INSTALL_PACKAGES`](https://developer.android.com/reference/android/Manifest.permission#INSTALL_PACKAGES) permission. If you need examples of such system apps, the [`fdroid privileged extension`](https://gitlab.com/fdroid/privileged-extension) app is a good example, or [`AuroraServices`](https://gitlab.com/AuroraOSS/AuroraServices)(_a fork of the fdroid privileged extension app_). These work in the background to invoke the system installer without alerting the user – smac89 Jan 21 '21 at 07:53

5 Answers5

24

Strictly speaking no, it is not possible: each Android package (.apk) file installed on the device is given its own unique Linux user ID, creating a sandbox for it and preventing it from touching other applications.
If an application would "install" another one, it couldn't give to the target a new user ID. Only the system applet, running at root level, can do that.

What the application can do is to indirectly invoke the package installer with the ACTION_VIEW intent and the application/vnd.android.package-archive MIME type: the system will launch the appropriate "viewer", which of course is the package installer.

Nice link about that topic: http://android.amberfog.com/?p=98

lornova
  • 6,667
  • 9
  • 47
  • 74
  • Just for completeness, I want to point out that your answer precludes a rooted device. – Caleb Hearth Jun 22 '10 at 18:02
  • Is there no way to get the system to ask the user for permission like Rpond suggested? – Anton Jun 22 '10 at 18:13
  • @Chapso: of course, on rooted devices you can do whatever you want, but in this case why asking if there is a "legitimate" way? – lornova Jun 22 '10 at 18:17
  • 1
    @Anton: sure, you have just to view the file, the system will detect the file type and launch the appropriate viewer, the installer in our case! – lornova Jun 22 '10 at 18:20
  • 1
    By the way... this is how to invoke the viewer: http://stackoverflow.com/questions/2637957/automatic-install-of-apk – lornova Jun 22 '10 at 18:20
  • The link in the answer helped a lot. – Anton Jun 24 '10 at 15:01
11

Yes. This is how the Swype beta works. What you basically do is download the new apk, and use some Intent (not sure which) to launch the Package Installer (and at this point it is a new activity and the user has to agree to install just like downloading from the Market).

Robby Pond
  • 73,164
  • 16
  • 126
  • 119
10

Try this:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path+"/yourapp.apk")), application/vnd.android.package-archive");
startActivity(intent);
wchargin
  • 15,589
  • 12
  • 71
  • 110
DroidlikeCode
  • 292
  • 3
  • 6
5


If the answer is NO. Then i wonder how facebook installs "Messenger" Application along with the "Facebook for Android" application?

If i'm not wrong, "Messenger" is also a different application from Main Facebook app.

Facebook For Android App will not ask to install Messenger App when we want to chat thru facebook app. It is already installed with facebook.

You can also install/uninstall Messenger application separately.

I may be wrong. I dont have complete information, but looking at the process and on applying little bit of logic i think we can install android application from another application. But how i'm too learning and looking for it .


So how must they have done it? Please correct me if i'm wrong.

Vishal
  • 59
  • 1
  • 5
  • I'm not sure. I can't test it out myself because my non-rooted android phone does not allow me to uninstall the Facebook app and reinstall it. I would guess that the Facebook app is allowed special privileges that normal apps do not have. Similar to how I am unable to uninstall the Facebook app from my phone without rooting my phone. I don't think Google would allow normal android applications to install other applications without the user's consent. Even application who are given Device Administration do not have the ability to install other apps. – Anton Jun 12 '12 at 13:09
  • 9
    That is done using multiple Launcher/Main activities in the Android Manifest xml. If you define two there, you see two shortcuts as launchers. – Ravindranath Akila May 28 '13 at 06:25
  • 3
    Facebook was also disabled from the Play Store at one point due to it "Breaking terms of service" by programatically modifying itself and it's other "apps" without going through the app store. Worth mentioning. – Graeme Dec 06 '13 at 13:44
  • 1
    @RavindranathAkila you are right. I too have figured it out. We can add launchers to the any activity and that will be shown in the apps menu list. – Vishal Jan 19 '16 at 01:37
0

If your app is root privlaged you can move the apk you want to install into /data/app and it will install when the device reboots

Partial Science
  • 330
  • 2
  • 6