使用movile数据从自己的服务器下载apk错误

时间:2017-03-23 21:28:10

标签: android

我是从我自己的服务器实现下载apk,并安装,当我用wifi下载它工作正常,但当movile与移动数据连接到互联网时传输非常低,并且apk不下载,不要给我一个错误。 我实现的代码是:

//下载实际的apk

                            InputStream inputStream = consumirWebService.ventaMovilUpdate("1", direccionUrlBase);
                            String pathApk = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+Dictionary.APK_NAME;
                            OutputStream os = new FileOutputStream(pathApk);
                            byte[] buffer = new byte[1024];
                            int bytesRead;
                            while((bytesRead = inputStream.read(buffer)) !=-1){
                                os.write(buffer, 0, bytesRead);
                            }
                            inputStream.close();
                            os.flush();
                            os.close();
                            //Install the new apk
                            PackageInfo info = IMAdministrador.this.getPackageManager().getPackageArchiveInfo(pathApk, PackageManager.GET_META_DATA);
                            File file = new File(pathApk);
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                            intent.putExtra(Intent.ACTION_PACKAGE_REPLACED, info.packageName);
                            intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            if(info.packageName != null){
                                IMAdministrador.INSTALL_APK_INFO.put(info.packageName, file);
                            }

我正在考虑通过使用rest webservices压缩的部分来下载apk。 apk的重量是5MB,下载每个部分的东西,如1Mb的部分,当我有五个部分,解压缩和安装。但我真的不知道我该怎么办呢。 或者如果你有任何好主意,我非常感谢你的帮助。 提前谢谢。

0 个答案:

没有答案