0

I have Android app on my server and also have php code like:

header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename="test.apk"');
readfile('test.apk');

My mobile with default web browser is downloading this file in the way of reading apk file on the screen. I expected some kind of dialogue like: save it as or/and where do you want to save it instead. What I am doing wrong? Is there any way to save it automatically, meaning without any dialogue?

Avyakt
  • 315
  • 4
  • 10
  • 1
    I think you mean "automatically"... – Marc B Aug 20 '12 at 13:59
  • @Avyakt what happens if you send `application/zip` as the content type. Since an APK is just a renamed zip archive, this should probably work as expected (if you're giving `.apk` as suggested appendix). – Lukas Knuth Aug 20 '12 at 14:32
  • @LukasKnuth exactly, but even if I did change it the result is the same. – Avyakt Aug 20 '12 at 14:46

2 Answers2

1

Try:

header("Cache-Control: public");
header("Content-Description: File Transfer");
header('Content-Type: application/vnd.android.package-archive');
header("Content-Transfer-Encoding: binary");    
header('Content-Disposition: attachment; filename="test.apk"');
readfile('C4A.apk');
Mike Mackintosh
  • 13,917
  • 6
  • 60
  • 87
  • It does not help, the mobile browser put content of apk file on screen as it should be read not downloaded. But thank you for suggestion. – Avyakt Aug 20 '12 at 14:15
  • In order to make it works I did change design, php code sends apk via email and it works for now. But, the question is without answer. – Avyakt Aug 21 '12 at 13:21
0

you should try one of these:

  1. check the mime type configuration on your server. APK Files
  2. add the apk extension to apache

also, check this question. However the server is .net, not php.

Community
  • 1
  • 1
rogcg
  • 10,451
  • 20
  • 91
  • 133
  • Thank you for your answer. Ad 2, I know this question but I do not know how could I apply these answers into my question. Ad 1, How can I check my server "my provider server" regarding to apk extension? – Avyakt Aug 20 '12 at 14:39
  • @Avyakt as mentioned, you can check on `/etc/mime.types` something like `application/vnd.android.package-archive apk` and you have to add this `AddType application/vnd.android.package-archive .apk` to `/etc/apache2/mods-available/mime.conf`. – rogcg Aug 20 '12 at 17:26
  • There is nothing wrong with apache apk extension, because I can download apk file on my PC via Firefox, but I cannot do that via default web browser on my mobile. – Avyakt Aug 21 '12 at 13:16