Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top