I am trying to download an Android APK file that is output by a php page. Downloading is success, But parsing package problem occur when try to install the apk file. Actually, access the filepath(/var/www/xxx/HelloWorldTest.apk) directly, this method installed completely.(no problem.) But I want to use the method that via the php source.
I have Android app on my server and also have php code like:
<?php
$path = "/var/www/xxx/";
$filename="HelloWorldTest.apk";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/vnd.android.package-archive");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($path . $filename));
readfile($path . $filename);
?>
Have HelloWorldTest(Android app) Manifest like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworldtest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloworldtest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
My setup: CentOS release 6.3 (Final),2.6.32-279.5.2.el6.x86_64, PHP 5.3.17 Android table Version:3.2.1 kernel version:2.6.36.3
There is difference of binary dump in using direct access method and using php method result.
direct access(success)
50 4B 03 04 14 00 08 08 08 00 F5 91 76 42 00 00
00 00 00 00 00 00 00 00 00 00 1C 00 04 00 72 65
73 2F 6C 61 79 6F 75 74 2F 61 63 74 69 76 69 74
79 5F 6D 61 69 6E 2E 78 6D 6C FE CA 00 00 6D 91
...
via php(install failed)
0A 0A 50 4B 03 04 14 00 08 08 08 00 F5 91 76 42
00 00 00 00 00 00 00 00 00 00 00 00 1C 00 04 00
72 65 73 2F 6C 61 79 6F 75 74 2F 61 63 74 69 76
69 74 79 5F 6D 61 69 6E 2E 78 6D 6C FE CA 00 00
.....
The problem seems to initial part [0A 0A] was added in binary code.