我试图下载一个由php页面输出的Android APK文件。 下载成功,但尝试安装apk文件时发生解析包问题。 其实,直接访问文件路径(/var/www/xxx/HelloWorldTest.apk),这个方法完全安装。(没问题。) 但是我想使用通过php源码的方法。在php下载Android二进制文件(apk),安装apk文件时解析错误包
我有我的服务器上的Android应用程序,也有PHP代码,如:
<?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);
?>
有无HelloWorldTest(Android应用程序)清单一样:
<?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>
我的设置: CentOS版本6.3(决赛),2.6.32-279.5.2.el6.x86_64,PHP 5.3.17 Android表版本:3.2.1内核版本:2.6.36.3
有b使用直接访问方法并使用php方法结果进行inary dump。通过PHP
直接访问(成功)
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
...
(安装失败)
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
.....
这个问题似乎初始部分[0A 0A]在二进制码中的溶液。