2

I have one server, and on that server I have uploaded one apk file. There is a button on my webpage that, when clicked, the application should be directly installed to device instead of being downloaded to local storage.

I need same functionality like we install apps from google play store.

If any one knows this, then it will be appreciated.

I have not found any solutions of this through google.

Thanks.

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74
  • Fortunately you can't do.. User have this permission to install or uninstall the apk. – Pankaj Kumar Feb 03 '14 at 07:00
  • @PankajKumar But we can do it from google play store right? so there must be some way to do same thing from our own server – Aamirkhan Feb 03 '14 at 07:01
  • You go like as user click on button just download the apk into the devices storage and then after ask user to install it into device. – GrIsHu Feb 03 '14 at 07:03
  • @GrIsHu ya we can do this that's fine, but my requirement is different, i want to install apk directly – Aamirkhan Feb 03 '14 at 07:06
  • @GrIsHu but we need to install apk directly, how?? – Make it Simple Feb 03 '14 at 07:15
  • You can not directly install apk. You need to always pass through the security breaches to install application in your device. As its done while installing apk from play store. – GrIsHu Feb 03 '14 at 07:16
  • HOw?? I think you did not observed the steps.. Google play doesn't install apk directly... user must involve into this. – Pankaj Kumar Feb 03 '14 at 07:23
  • @PankajKumar Yes first application is downloaded but after download completed apk directly installed on device, for that apk is not stored on local storage – Aamirkhan Feb 03 '14 at 07:26
  • Then what is the problem. After download, install the apk and remove that from downloaded location.. – Pankaj Kumar Feb 03 '14 at 07:34
  • @PankajKumar Yeah i also think same way – Aamirkhan Feb 03 '14 at 07:34
  • In fact no installer app is needed to perform the installation - you can provide the .apk directly from the web page and have that generate a user confirmation dialog just as downloading it and using an Intent would. See http://stackoverflow.com/questions/3569313/cant-install-apk-hosted-my-own-apache-server for the details. – Chris Stratton Feb 26 '14 at 18:38

3 Answers3

2

This is not possible. Fortunately. Imagine the security breach this would be. Any Website could force install apps. This would open the doors for any kind of Virus.

FD_
  • 12,947
  • 4
  • 35
  • 62
1

Any third party cannot install the application of their own on the Android Device directly. Otherwise they need some root permission that should be declared in device Kernel. Google Play can directly install by sending commands to Play Store to install the particular app as Google is in fact the owner of Android and indirectly Device Administrator which have full access to your device kernel.

Shankar Regmi
  • 854
  • 1
  • 7
  • 16
  • oh!! so u give a negative vote for it :-) . How could you be confirmed that the detail is mistaken.. any proof or what ? – Shankar Regmi Feb 27 '14 at 05:51
1

You cannot do that as our friends advised you. I have tried by these ways for installing APK from my own server

  1. You can download the APK from the server and save it in some folder
  2. Add permission in manifest
    <uses-permission android:name="android.permission.INSTALL_PACKAGES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Use this demo code for downloading and installing the APK

Downloading APK from server

String PATH = Environment.getExternalStorageDirectory()+ "/yourpath/";
                        File file = new File(PATH); 
                        if (!file.exists()) {
                            file.mkdirs();
                        }

                            File outputFile = new File(file,
                                    "your.apk");
                            if (outputFile.exists()) {
                                outputFile.delete();
                            }

                            FileOutputStream fileOuputStream = new FileOutputStream(
                                    outputFile);
                            fileOuputStream.write(bResponse);
                            fileOuputStream.close();

Installation of APK after Download completes

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(Environment
    .getExternalStorageDirectory()+ "/your path/"+ "yourapkname.apk")),
    "application/vnd.android.package-archive");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

3.After Installation you can delete the APK from folder location

Kalai.G
  • 1,610
  • 13
  • 22
  • 1
    **DO NOT** tell people to put the INSTALL_PACKAGES permission in the manifest, as the documentation clearly states that this is "Not for use by third-party applications" and it **will not work**. Triggering an install dialog for the user as you are doing here with an Intent does not require this permission. Also, this does not answer the question actually asked - in fact, no application is needed at all. – Chris Stratton Feb 26 '14 at 18:31
  • @ChrisStratton Thanks for the clarification,it's useful – Aamirkhan Feb 06 '17 at 06:08