简体   繁体   English

Apk文件下载在Android中使用Java时出错

[英]Apk File download Error using Java in Android

.I followed this tutorial and getting errors "PARSING ERROR THERE IS A PROBLEM PARSING THE PACKAGE" . 我遵循了这个教程并得到了错误“PARSING ERROR是一个问题包括包装” I have check the result in Android Device Samsung Galaxy S3. 我已在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;
 }}  
  }

I am getting this error after Complete Action using dialog when trying to press either PACKAGE INSTALLER or VERIFY AND INSTALL in both cases same error. Complete Action using对话框后,我尝试按下PACKAGE INSTALLERVERIFY AND INSTALL在两种情况下都出现此错误相同的错误。 清单文件

Change your manifes to like 改变你的表现形象

在此输入图像描述

This should work fine i think.. If not worked please post your tutorial link i missed it.. i need to check it.. and i will update answer... and also mention how you are installing app wether by eclipse or by some other process like importing apk... IF importing apk to real device means please check ur device version, If its s3 mans it has ICS api level includes 14 or 15 so change that.. if its jellly bean means you can use up to 18 这应该工作正常我认为..如果没有工作,请发布你的教程链接我错过了..我需要检查它...我会更新答案...还提到你是如何通过日食或某些人安装应用程序其他进程如导入apk ...如果导入apk到真实设备意味着请检查你的设备版本,如果它的s3勒芒它有ICS api级别包括14或15所以改变..如果它的果冻豆意味着你可以使用多达18

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

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