java - 在 Android 中使用 Java 的 Apk 文件下载错误

标签 java android android-install-apk

。我遵循了本教程并收到错误“解析错误,解析包时出现问题”。我已经在 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 INSTALLERVERIFY AND INSTALL 时,我在 Complete Action using 对话框后收到此错误,在这两种情况下都是相同的错误. Manifest file

最佳答案

将您的 list 更改为喜欢

enter image description here

我认为这应该可以正常工作..如果没有工作请发布您的教程链接我错过了..我需要检查它..我会更新答案... 并提及您是如何通过 eclipse 或通过导入 apk 等其他过程安装应用程序的...如果将 apk 导入真实设备意味着请检查您的设备版本,如果它的 s3 mans 它具有 ICS api 级别包括 14 或 15 所以更改那..如果它的果冻 bean 意味着你最多可以使用 18

关于java - 在 Android 中使用 Java 的 Apk 文件下载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21159636/

相关文章:

java - 国会图书馆 Web 服务上的 Java 和 XPath 错误

android - 向 SD 卡写入文本时出现 EACCES(权限被拒绝)

android - 使用 ACTION_CREATE_DOCUMENT 编写的文件在 Google Drive 上是空的,但在本地存储中不是

android - 使用 .apk 文件访问源代码

Android 平板电脑不允许我一次安装多个应用程序

firebase - Flutter 应用程序作为 .apk 工作,但 "installation failed"使用 firebase 分发

java - 读出 Java 中 Mp3 歌曲的时间/长度/持续时间

VM Survivor Old Gen 中的 Java Survivor1、Survivor2

java - 在Android中调用一个变量的Intent

安卓 MVP : One Activity with Multiple Fragments