0

这样一个美好的夜晚,我写信询问我是否可以提供帮助,并通过 listView 和 presslong 获取以下代码,获取文件的路径,尝试打开服务: http://www .convertapi.com/excel-pdf-api

我不必使用 webview,或者可以使用隐藏的方式谢谢

代码是:

mPrefs = getSharedPreferences("RutaPath", Context.MODE_PRIVATE);
                        String rutasave = mPrefs.getString("Externa", "");

                        String resultcode = "0";

                        HttpPost httppost = new HttpPost("http://do.convertapi.com/Excel2Pdf/json");

                        MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );

                        // For File parameters
                        file=new File(rutasave+"prueba.xls");
                       //Toast.makeText(this,"cargando: " +rutasave+"prueba.xls",Toast.LENGTH_SHORT).show();
                        outputDir=rutasave;
                        entity.addPart("file", new FileBody(file, "binary/octet-stream"));//"file"

                        httppost.setEntity( entity );

                        HttpClient httpclient = new DefaultHttpClient();

                      // return new Boolean(true);//eliminar despues
                        try {
                            HttpResponse response = httpclient.execute(httppost);
                            Header rcHeader = response.getFirstHeader("result");
                            if(rcHeader != null){

                                resultcode = rcHeader.getValue();

                                if("True".equals(resultcode)){


                                    filesize = response.getFirstHeader("filesize").getValue();
                                    filename = response.getFirstHeader("OutputFileName").getValue();

                                    //Toast.makeText(this,"Archivo: " +filename,Toast.LENGTH_SHORT).show();
                                    HttpEntity hentity = response.getEntity();
                                    if(hentity != null){

                                        InputStream istream = hentity.getContent();
                                        File file = new File(outputDir+filename+".pdf");//outputDir  File.separator
                                        FileOutputStream ostream = new FileOutputStream(file);

                                        byte[] b = new byte[1024];
                                        int num = 0;
                                        while( (num = istream.read(b, 0, b.length)) > 0)
                                            ostream.write(b, 0, num);
                                        istream.close();
                                        ostream.flush();
                                        ostream.close();
                                        return new Boolean(true);

                                    }
                                }
                            }

                        } catch (ClientProtocolException e) {
4

0 回答 0