解析错误,而安装下载.apk文件 [英] Parse error while installing downloaded .apk file

查看:272
本文介绍了解析错误,而安装下载.apk文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜两周后再次我开始我的研究以及与此错误挣扎*的解析错误:的*有一个问题解析包

我的实施范围是想从那里我有更新的apk文件服务器更新我的应用程序,并使用服务。现在我在舞台边缘,我可以下载从服务器的文件下载我通过它我的应用我可以能够通过manually.But安装
我的范围,如文件是从服务器downloade后,它会自动调用
在安装应用程序的弹出窗口。而安装此我得到上述error.i问这个问题谁在这里问了同样的问题以前都试过了。

这是我的code:

 公共类MYSERVICE扩展服务{
字符串的versionName;@覆盖
公众的IBinder onBind(意向意图){
    // TODO自动生成方法存根
    返回null;
}@覆盖
公共无效的onCreate(){
    Toast.makeText(这一点,我的服务创建Toast.LENGTH_LONG).show();}@覆盖
公共无效的onDestroy(){
    Toast.makeText(这一点,我的服务已停止,Toast.LENGTH_LONG).show();}@覆盖
公共无效调用onStart(意向意图,诠释startid){
    尝试{
        的versionName = getPackageManager()。getPackageInfo(getPackageName(),
                0).versionName;
    }赶上(ē的NameNotFoundException){
        // TODO自动生成catch块
        e.printStackTrace();
    }     DownloadFromUrl();
}公共无效DownloadFromUrl(){//这是下载方法
      尝试{
              网址URL =新的URL(http://61.12.5.34:10140/test/UpateTest.apk);
              字符串文件=YeldiUpateTest.apk;              长STARTTIME = System.currentTimeMillis的();              / *打开到URL的连接。 * /
              URLConnection的UCON = url.openConnection();              / *
               *定义InputStreams从URLConnection的阅读。
               * /
              InputStream为= ucon.getInputStream();
              二BufferedInputStream为=新的BufferedInputStream(是);              / *
               *读取字节到缓冲区,直到有没有更多阅读(-1)。
               * /
              ByteArrayBuffer BAF =新ByteArrayBuffer(50);
              INT电流= 0;
              而((电流= bis.read())!= - 1){
                      baf.append((字节)电流);              }              / *读取转换为字符串的字节数。 * /
              FOS的FileOutputStream = openFileOutput(文件,Context.MODE_PRIVATE);
              Log.v(WSD,写);
              fos.write(baf.toByteArray());
              fos.close();
              Log.d(下载时间,下载就绪
                              +((System.currentTimeMillis的() - 的startTime)/ 1000)
                              +秒);              安装();
      }赶上(IOException异常五){
              Log.d(的ImageManager,错误:+ E);
      }
 }

这是我的安装​​方法():

 无效安装()
{     文件路径= getFileStreamPath(UpateTest.apk);     意向意图=新意图(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.fromFile(路径),应用程序/ vnd.android.package归档);
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(意向);
}


解决方案

终于可以能够安装APK我这是从我的服务器下载没有任何解析Error.I与外部存储尝试它happend没有任何error.to店在内部存储的APK,并要安装意味着u需要改变你的

 的FileOutputStream FOS = openFileOutput(文件,Context.MODE_PRIVATE)

Context.MODE_WORLD_READABLE 。我喜欢添加权限 INSTALL_PACKAGES

Hi after Two weeks again i started my research and struggling with this Error *Parse Error:*There is a problem parsing package.

Scope of my implementation is am trying to update my app from a server where i have the updated apk file and am downloading it through my app using service .Now am at edge of the Stage i can download the file from that server an i can able to install it by manually.But my scope is like after file is downloade from the Server it should automatically invoke the installing app popup window .while installing this am getting the above error.i have tried before asking this question whoever asked the same issue here.

This is my code:

public class Myservice extends Service {
String versionName;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

}

@Override
public void onDestroy() {
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();

}

@Override
public void onStart(Intent intent, int startid) {
    try {
        versionName = getPackageManager().getPackageInfo(getPackageName(),
                0).versionName;
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



     DownloadFromUrl();


}

public void DownloadFromUrl() {  //this is the downloader method
      try {
              URL url = new URL("http://61.12.5.34:10140/test/UpateTest.apk");
              String  file ="YeldiUpateTest.apk";

              long startTime = System.currentTimeMillis();

              /* Open a connection to that URL. */
              URLConnection ucon = url.openConnection();

              /*
               * Define InputStreams to read from the URLConnection.
               */
              InputStream is = ucon.getInputStream();
              BufferedInputStream bis = new BufferedInputStream(is);

              /*
               * Read bytes to the Buffer until there is nothing more to read(-1).
               */
              ByteArrayBuffer baf = new ByteArrayBuffer(50);
              int current = 0;
              while ((current = bis.read()) != -1) {
                      baf.append((byte) current);

              }

              /* Convert the Bytes read to a String. */
              FileOutputStream fos = openFileOutput(file, Context.MODE_PRIVATE);
              Log.v("wsd", "write");
              fos.write(baf.toByteArray());
              fos.close();
              Log.d("Download time", "download ready in"
                              + ((System.currentTimeMillis() - startTime) / 1000)
                              + " sec");

              install();
      } catch (IOException e) {
              Log.d("ImageManager", "Error: " + e);
      }
 }

and this is my install method():

void install()
{

     File path=getFileStreamPath("UpateTest.apk");

     Intent intent=new Intent(Intent.ACTION_VIEW);
     intent.setDataAndType(Uri.fromFile(path), "application/vnd.android.package-archive");
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
}

解决方案

Finally i can able to install my apk which was downloaded from my server without any Parse Error.I tried with external storage it was happend without any error.to store the apk in internal storage and want to install means u need to change Your

FileOutputStream fos = openFileOutput(file, Context.MODE_PRIVATE)

to Context.MODE_WORLD_READABLE. and i added permissions like INSTALL_PACKAGES.

这篇关于解析错误,而安装下载.apk文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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