android "can not display PDF (name.pdf is of invalid format)"

0

I am downloading a document with volley and it does not allow me to open it, it shows the message

  

can not display PDF (name.pdf is of invalid format)

Also comment that the service returns me a byte[] with a weight, and debugging in the android part, I relive a greater weight. The code is as follows:

InputStreamVolleyRequest request = new InputStreamVolleyRequest(Request.Method.POST, uri,
            new Response.Listener<byte[]>() {
                @Override
                public void onResponse(byte[] response) {                        
                    try {
                        if (response!=null) {

                            if(Build.VERSION.SDK_INT>22){
                                requestPermissions(new String[] {"android.permission.WRITE_EXTERNAL_STORAGE","android.permission.READ_EXTERNAL_STORAGE"}, 1);
                            }

                            File baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
                            baseDir.mkdirs();
                            File carpeta = new File(baseDir + nombre_carpeta);
                            carpeta.mkdirs();
                            File file = new File(baseDir, documento.NombreFichero.replace("\","/"));
                            try {
                                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                                bos.write(response);
                                bos.flush();
                                bos.close();
                                Log.d("NEWFILE", file.getAbsolutePath());
                                Toast.makeText(getActivity(), "Descarga completa.", Toast.LENGTH_LONG).show();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                        }
                    } catch (Exception e) {
                        Log.d("KEY_ERROR", "UNABLE TO DOWNLOAD FILE");
                        e.printStackTrace();
                    }
                }
            } ,new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }, (HashMap<String, String>) params);

    RequestQueue mRequestQueue = Volley.newRequestQueue(getActivity().getApplicationContext(), new HurlStack());
    mRequestQueue.add(request);

Thanks in advance

    
asked by Juan 04.06.2018 в 16:04
source

0 answers