软件自定义更新程序,已签名的 Apk 安装 PARSE ERROR
Software Custom Updater, Signed Apk install PARSE ERROR
我正在创建应用程序自定义更新程序,更新时出现解析错误。
我使用 AsyncTask 下载签名的 apk
output = new FileOutputStream(context.getFilesDir()+"/update.apk");
下载成功,然后我尝试运行这样的apk:
File file = new File("file://"+context.getFilesDir(), "update.apk");
file.setReadable(true, false);
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);
应用程序开始更新,但随后出现了我的问题,
Parse Error: An error occurred while parsing the package
我做错了什么?
找到解决方案..
我忘记添加从外部存储读取的权限,将此行添加到
AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
AsyncTask
@Override
protected String doInBackground (String...sUrl){
......
File sd = Environment.getExternalStorageDirectory();
File outputFile = new File(sd, "/download/update.apk");
output = new FileOutputStream(outputFile);
......
}
@Override
protected void onPostExecute(String result) {
......
File sd = Environment.getExternalStorageDirectory();
File inputFile = new File(sd, "/download/update.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW);
promptInstall.setDataAndType(Uri.fromFile(inputFile), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);
......
}
我正在创建应用程序自定义更新程序,更新时出现解析错误。
我使用 AsyncTask 下载签名的 apk
output = new FileOutputStream(context.getFilesDir()+"/update.apk");
下载成功,然后我尝试运行这样的apk:
File file = new File("file://"+context.getFilesDir(), "update.apk");
file.setReadable(true, false);
Intent promptInstall = new Intent(Intent.ACTION_VIEW)
.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);
应用程序开始更新,但随后出现了我的问题,
Parse Error: An error occurred while parsing the package
我做错了什么?
找到解决方案..
我忘记添加从外部存储读取的权限,将此行添加到
AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
AsyncTask
@Override
protected String doInBackground (String...sUrl){
......
File sd = Environment.getExternalStorageDirectory();
File outputFile = new File(sd, "/download/update.apk");
output = new FileOutputStream(outputFile);
......
}
@Override
protected void onPostExecute(String result) {
......
File sd = Environment.getExternalStorageDirectory();
File inputFile = new File(sd, "/download/update.apk");
Intent promptInstall = new Intent(Intent.ACTION_VIEW);
promptInstall.setDataAndType(Uri.fromFile(inputFile), "application/vnd.android.package-archive");
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(promptInstall);
......
}