简体   繁体   English

解析错误-以编程方式安装apk

[英]Parse Error - Installing apk programmatically

I am trying to install an apk file programmatically. 我正在尝试以编程方式安装apk文件。 I referred this site for doing it. 我推荐这个网站

Now the apk file is downloaded from an url and placed in SDCard. 现在,可以从URL下载apk文件并将其放置在SDCard中。 When I try to install it on the device using Intent method, 当我尝试使用Intent方法将其安装在设备上时,

It is popping up following error 错误后弹出

Emulator: 仿真器:

 "Parse Error - There is a problem parsing the package",
Logcat(W) : "Unable to read AndroidManifest.xml of /mnt/sdcard/download/myapp.apk",
Logcat(W) : "java.ioException: AndroidManifest.xml",
Logcat(W) : "Parse error when parsing manifest. Discontinuing installation".
Logcat(E) : "java.lang.SecurityException",
Logcat(E) : "java.lang.NullPointerException".

Note: 1) I was able to install the same .apk file using adb. 注意:1)我能够使用adb安装相同的.apk文件。 2) I changed this .apk file to .pdf format before sending it to Server Team and then they changed it back to .apk. 2)我将此.apk文件更改为.pdf格式,然后再将其发送给Server Team,然后他们将其更改为.apk。 I am adding this coz there might be chances for error due to format conversion. 我正在添加此内容,因为格式转换可能会出现错误。

Installation can give the specified error at least in following cases: 安装至少在以下情况下会产生指定的错误:

  • Name of the package is changed after signing: Use the exact name as the signed package is (instead, adjust the name in Manifest) 签名后更改包的名称:使用与签名的包相同的名称(相反,在清单中调整名称)

  • Package is compiled against on higher API level: Correct the API level in Manifest file 在更高的API级别上对软件包进行编译:更正清单文件中的API级别

  • Package is executed from SD-card: Run (install) the apk -file from phones memory OR use adb command to install it 程序包从SD卡执行:从手机内存中运行(安装)apk -file或使用adb命令进行安装

Please check this code 请检查此代码

  private void installApk(){
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                            Uri uri = Uri.fromFile(new File("/sdcard/path"));
                            intent.setDataAndType(uri, "application/vnd.android.package-archive");
                            startActivity(intent);}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM