在Android中使用Java APK文件下载错误 [英] Apk File download Error using Java in Android

查看:184
本文介绍了在Android中使用Java APK文件下载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。我跟着这个教程,并得到错误分析错误有一个问题解析PACKAGE。我的检查结果在Android设备三星Galaxy S3。

.I followed this tutorial and getting errors "PARSING ERROR THERE IS A PROBLEM PARSING THE PACKAGE". I have check the result in Android Device 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;
 }}  
  }

我后,收到此错误使用对话框试图preSS时完成动作或者安装程序包验证并安装在这两种情况下同样的错误。

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.

推荐答案

更​​改manifes喜欢

Change your manifes to like

这应该工作的罚款,我认为。如果没有成功,请发表您的我错过了教程链接..我需要检查它..我会更新答案... 也别说你是如何安装的应用程序阉羊被日食或其他一些过程是进口的apk ...如果导入的apk到真实的设备是指请UR设备版本,如果它的S3芒已经ICS API层次包括14或15这样的变化这..如果jellly豆意味着您可以使用多达18

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

这篇关于在Android中使用Java APK文件下载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆