Search code examples
androidiphonesmartphone

How to install application directly to device from web


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.


Solution

  • 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