Search code examples
installationzipapkshared-hosting

.apk file getting installed as .zip from my web server


I am serving an apk via my shared hosting server, but when users navigate to the link and downloads the .apk it gets downloaded as an .zip on various devices. How can I ensure that it gets downloaded as an .apk?


Solution

  • I came up with the following solution:

    Create an index.php in a folder which contains:

    <?php
    if(isset($_GET['apk'])) { header('Content-Disposition: attachment; filename="<yourappname>.apk"'); 
    exit(file_get_contents('cric.apk')); }
    header("Location: https://<yoursitename>.com/<yourfolder>/<yourappname>.apk"); 
    exit();
    ?>
    

    Add the following line in your .htaccess file. You can also create a new .htaccess inside that particular folder

    AddType application/vnd.android.package-archive .apk
    

    This adds the android apk mime-type.

    Now users can navigate to https://yoursitename.com/yourfolder and install the apk.