我正在使用DownloadManager从服务器下载. apk文件下载后,当我试图手动安装应用程序时,它会给出解析错误,并显示消息"解析包时出现问题"。
但相同的apk当我下载通过浏览器和复制到SD卡然后安装,然后它是安装成功。
所以希望minsdkversion没有问题,我已经检查了未知来源。
我的代码是这样下载的apk文件
public class UpdateCheckerService extends Service {
UpdateChecker update_checker;
DownloadManager downloadManager;
String Download_path="http://www.xxxxx.com/mobile_api/xxxxxx.apk";
SharedPreferences preferenceManager;
String Download_ID = "100";
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
public void onCreate()
{
System.out.println("SERVICE ************ CREATED");
}
public void onStart(Intent intent1, int start_id)
{
System.out.println("Service started");
IntentFilter intentFilter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
registerReceiver(downloadReceiver, intentFilter);
System.out.println("Service started");
if(isNetworkAvailable())
{
if(true)
{
System.out.println("Update AVAAILLL:");
preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);
downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
.mkdirs();
Uri Download_Uri = Uri.parse(Download_path);
DownloadManager.Request request = new DownloadManager.Request(Download_Uri);
long download_id = downloadManager.enqueue(request.setTitle("Downloading...")
.setDescription("xxxx").setMimeType("application/vnd.android.package-archive").setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
"xxxxx.apk"));
Editor PrefEdit = preferenceManager.edit();
PrefEdit.putLong(Download_ID, download_id);
PrefEdit.commit();
}
}
}
public void onDestroy()
{
}
private BroadcastReceiver downloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(preferenceManager.getLong(Download_ID, 0));
Cursor cursor = downloadManager.query(query);
if(cursor.moveToFirst()){
int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = cursor.getInt(columnIndex);
int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
int reason = cursor.getInt(columnReason);
if(status == DownloadManager.STATUS_SUCCESSFUL){
//Retrieve the saved download id
long downloadID = preferenceManager.getLong(Download_ID, 0);
ParcelFileDescriptor file;
try {
file = downloadManager.openDownloadedFile(downloadID);
Toast.makeText(UpdateCheckerService.this,
"File Downloaded: " + file.toString(),
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(UpdateCheckerService.this,
e.toString(),
Toast.LENGTH_LONG).show();
}
}else if(status == DownloadManager.STATUS_FAILED){
Toast.makeText(UpdateCheckerService.this,
"FAILED!\n" + "reason of " + reason,
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_PAUSED){
Toast.makeText(UpdateCheckerService.this,
"PAUSED!\n" + "reason of " + reason,
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_PENDING){
Toast.makeText(UpdateCheckerService.this,
"PENDING!",
Toast.LENGTH_LONG).show();
}else if(status == DownloadManager.STATUS_RUNNING){
Toast.makeText(UpdateCheckerService.this,
"RUNNING!",
Toast.LENGTH_LONG).show();
}
}
}
};
}
这是logcat
11-25 16:31:58.195: D/asset(3422): failed to open Zip archive '/mnt/sdcard/Download/SavariLocal.apk'
11-25 16:31:58.210: W/PackageParser(3422): Unable to read AndroidManifest.xml of /mnt/sdcard/Download/SavariLocal.apk
11-25 16:31:58.210: W/PackageParser(3422): java.io.FileNotFoundException: AndroidManifest.xml
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlAssetNative(Native Method)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:486)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.res.AssetManager.openXmlResourceParser(AssetManager.java:454)
11-25 16:31:58.210: W/PackageParser(3422): at android.content.pm.PackageParser.parsePackage(PackageParser.java:402)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.packageinstaller.PackageUtil.getPackageInfo(PackageUtil.java:79)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.packageinstaller.PackageInstallerActivity.onCreate(PackageInstallerActivity.java:242)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
11-25 16:31:58.210: W/PackageParser(3422): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 16:31:58.210: W/PackageParser(3422): at android.os.Looper.loop(Looper.java:130)
11-25 16:31:58.210: W/PackageParser(3422): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-25 16:31:58.210: W/PackageParser(3422): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 16:31:58.210: W/PackageParser(3422): at java.lang.reflect.Method.invoke(Method.java:507)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-25 16:31:58.210: W/PackageParser(3422): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-25 16:31:58.210: W/PackageParser(3422): at dalvik.system.NativeStart.main(Native Method)
11-25 16:31:58.210: W/PackageInstaller(3422): Parse error when parsing manifest. Discontinuing installation
请告诉我如何解决这个问题,以及我错在哪里。
先谢了。
2条答案
按热度按时间xv8emn3q1#
我有同样的问题,我发现,卸载应用程序后,比重新安装apk帮助。
有another solution,我没有尝试,但它可能是有用的。
bmp9r5qi2#
我之前遇到过这个问题,我是这样调试的,首先通过终端adb install path_to_your_app/name_of_your_app.apk安装APK,如果出现错误信息:adb:无法安装您的应用程序的名称.apk:故障[安装失败无匹配ABIS:未能提取本机库,这意味着您正在生成的体系结构与仿真程序体系结构不匹配。
由于这是一个来自外部源的APK,您可能需要考虑重新打包它并根据您的设备架构进行构建。您可以使用此工具:https://ibotpeaches.github.io/Apktool/
希望这能帮上忙