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

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

问题描述

.我按照本教程操作,但遇到错误解析包时出现问题解析包".我已经在 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;
 }}  
  }

我在 Complete Action using 对话框后尝试按下 PACKAGE INSTALLERVERIFY AND INSTALL 后出现此错误.

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.

推荐答案

改变你的宣言

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

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

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