。我遵循了本教程并收到错误“解析错误,解析包时出现问题”。我已经在 Android 设备 Samsung Galaxy S3 中检查了结果。
package com.mrfs.android.surveyapp.activities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
public class ApkFileAsync extends Activity
{
UpdateApp updateAppInstance;
@Override
public void onCreate(Bundle savedBundleInstance)
{
super.onCreate(savedBundleInstance);
updateAppInstance = new UpdateApp();
updateAppInstance.setContext(getApplicationContext());
updateAppInstance.execute("http://demo.ingresssolutions.com/proposalmanagement/services/user/getApkFile");
}
private class UpdateApp extends AsyncTask<String,Void,Void>{
private Context context;
public void setContext(Context contextf){
context = contextf;
}
@Override
protected Void doInBackground(String... arg0) {
try {
URL url = new URL(arg0[0]);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("POST");
c.setDoOutput(true);
c.connect();
String PATH = "/mnt/sdcard/Download/";
File file = new File(PATH);
file.mkdirs();
File outputFile = new File(file,"surveyapp.apk");
if(outputFile.exists()){
outputFile.delete();
}
FileOutputStream fos = new FileOutputStream(outputFile);
InputStream is = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
/* Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/Download/update.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);*/ // without this flag android returned a intent error!
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
context.startActivity(intent);
} catch (Exception e) {
Log.e("UpdateAPP", "Update error! " + e.getMessage());
}
return null;
}}
}
在尝试按 PACKAGE INSTALLER
或 VERIFY AND INSTALL
时,我在 Complete Action using
对话框后收到此错误,在这两种情况下都是相同的错误.
最佳答案
将您的 list 更改为喜欢
我认为这应该可以正常工作..如果没有工作请发布您的教程链接我错过了..我需要检查它..我会更新答案... 并提及您是如何通过 eclipse 或通过导入 apk 等其他过程安装应用程序的...如果将 apk 导入真实设备意味着请检查您的设备版本,如果它的 s3 mans 它具有 ICS api 级别包括 14 或 15 所以更改那..如果它的果冻 bean 意味着你最多可以使用 18
关于java - 在 Android 中使用 Java 的 Apk 文件下载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21159636/