如何在android下载内容作为pdf文件?

时间:2014-04-04 04:18:16

标签: android pdf webview

我正在开发一个应用程序,因为我可以显示源和目标之间的路由并显示有关该路由的一些描述。现在我正在尝试将该说明下载到我的手机中。我被搜索如此,但我没有找到任何相关的例子。请分享这个

的任何例子

mycode的

private class GetRouteTask extends AsyncTask<String, Void, String>{
    private ProgressDialog pDialog;
    String response="";
    private  WeakReference<ShowRoutesInMap> weakRef;

    //public ArrayList<String> alter;
    public ArrayList<String> route1;
    public ArrayList<String> route2;
    public ArrayList<String> route3;

    PolylineOptions rectLine = null;
    PolylineOptions rectLine1 = null;
    PolylineOptions rectLine2 = null;
    PolylineOptions rectLine3 = null;
    public ArrayList<LatLng> directionPoint;
    private ArrayList<String> alter;

    public GetRouteTask(ShowRoutesInMap context){
        this.weakRef =new WeakReference<ShowRoutesInMap>(context);
    }
    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
         pDialog = new ProgressDialog(ShowRoutesInMap.this);
         if(!isFinishing()){
         pDialog.setMessage("Please wait For TrafficJam Route...");
         pDialog.setCancelable(false);
         pDialog.show();
         }
    }
    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub
        try{
            if(sourcePosition!=null && destinationPostion!=null){
        document = v2GetRouteDirection.getDocument(sourcePosition, destinationPostion,GMapV2Direction.MODE_DRIVING);
            }
        }
        catch(Exception e){
            return "exception caught";
        }

        response = "Success";
        return response;
    }
    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
    //  if(!isFinishing()){
            pDialog.dismiss();
    //      }

         route1 = new ArrayList<String>();
         route2 = new ArrayList<String>();
         route3 = new ArrayList<String>();
        if(result.equalsIgnoreCase("exception caught")){
            Toast.makeText(getApplicationContext(), "INVALID VALUES", Toast.LENGTH_LONG).show();
        }
        else{
        if (weakRef.get() != null && ! weakRef.get().isFinishing()){

    //  if(response.equalsIgnoreCase("Success")){
            alter = v2GetRouteDirection.getAlternativeRoutes(document);


            int duration = v2GetRouteDirection.getDurationValue(document);
            Log.e("TRAFFIC DURATIONTIME",""+duration);
            int trfficClearTime = v2GetRouteDirection.getDistanceValue(document);
            Log.e("TRAFFIC TIME", ""+trfficClearTime);

            for( j=0;j<alter.size();j++){

                 directionPoint =v2GetRouteDirection.getDirection(document, j);

                ArrayList<String> desc = v2GetRouteDirection.getDescription(document,j);

                if(j==0){

                    for(int l=0;l<desc.size();l++){
                    route1.add(desc.get(l));

                    Log.e("ROUTE1", desc.get(l).replace("\\<.*?>",""));
                    }
                }
                    else if(j==1){

                        for(int l=0;l<desc.size();l++){
                        route2.add(desc.get(l));
                        Log.e("ROTE2", desc.get(l).replace("\\<.*?>",""));
                    }
                    }
                        else if(j==2){

                            for(int l=0;l<desc.size();l++){
                            route3.add(desc.get(l));
                            Log.e("ROTE2", desc.get(l).replace("\\<.*?>",""));
                        }
                    }
            rectLine = new PolylineOptions().width(5).color(Color.RED).geodesic(true);

                for (int i = 0; i < directionPoint.size(); i++) {

                    rectLine.add(directionPoint.get(i));

                }

                googleMap.addPolyline(rectLine);


                getMarkersOnMap(googleMap);

                 alterRoutes1.setText(""); 


                if(alter.size()==1){
                     alterRoutes1.setText(alter.get(0)); 
                }
                else if(alter.size()>=1 && alter.size()<=2){
                    alterRoutes1.setText(alter.get(0)); 
                    alterRoutes2.setText(alter.get(1));
                }
                else if(alter.size()>=1 && alter.size()<=3){
                    alterRoutes1.setText(alter.get(0)); 
                    alterRoutes2.setText(alter.get(1));
                    alterRoutes3.setText(alter.get(2));
                }
            }
        }
        alterRoutes1.setOnClickListener(new OnClickListener() {

            private ArrayList<LatLng> directionPoint1;

            @Override
            public void onClick(View v) {                   // TODO Auto-generated method stub
                googleMap.clear();
            //    ArrayList<String> alter = v2GetRouteDirection.getAlternativeRoutes(document);
                 rectLine1 = new PolylineOptions().width(5).color(Color.GREEN).geodesic(true);
                 for( int k=0;k<alter.size();k++){
                     directionPoint1 =v2GetRouteDirection.getDirection(document, k);
                     for (int i = 0; i < directionPoint1.size(); i++) {
                            if(k==0){
                            rectLine1.add(directionPoint1.get(i));

                            }
                        }
                     googleMap.addPolyline(rectLine1);
                     getMarkersOnMap(googleMap);
                 }  

                for(int i=0;i<route1.size();i++){
                    showDirection.append(route1.get(i).replaceAll("\\<.*?>",""));
                    }
            }
        });
        alterRoutes2.setOnClickListener(new OnClickListener() {

            private ArrayList<LatLng> directionPoint2;

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                googleMap.clear();
                showDirection.setText("");
                 rectLine2 = new PolylineOptions().width(5).color(Color.MAGENTA).geodesic(true);
                 for( int k=0;k<alter.size();k++){
                     directionPoint2 =v2GetRouteDirection.getDirection(document, k);
                     for (int i = 0; i < directionPoint2.size(); i++) {
                            if(k==1){
                            rectLine2.add(directionPoint2.get(i));
                          }
                        }
                        googleMap.addPolyline(rectLine2);
                        getMarkersOnMap(googleMap);
                 }  
                for(int i=0;i<route2.size();i++){
                showDirection.append(route2.get(i).replaceAll("\\<.*?>",""));
                }
            }
        });
        alterRoutes3.setOnClickListener(new OnClickListener() {
            private ArrayList<LatLng> directionPoint3;
            int count=0;
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                googleMap.clear();
                showDirection.setText("");
                 rectLine3 = new     
   PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
                 for( int k=0;k<alter.size();k++){
                     directionPoint3 
 =v2GetRouteDirection.getDirection(document, k);
                     for (int i = 0; i < directionPoint3.size(); i++) {
                            if(k==2){

 rectLine3.add(directionPoint3.get(i));

                           }
                        }
                        googleMap.addPolyline(rectLine3);
                        getMarkersOnMap(googleMap);

                        }
                for(int i=0;i<route3.size();i++){
                showDirection.append(""+ ++count);
                    showDirection.append(route3.get(i).replaceAll("\\<.*?
    >",""));
                    }
            }
        });


        }
    }
}
  public void getMarkersOnMap(GoogleMap gmap){
     Markeropition1.position(sourcePosition).icon(BitmapDescriptorFactory
            .defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
            .flat(true);
    Markeropition2.position(destinationPostion).icon(BitmapDescriptorFactory
             .defaultMarker(BitmapDescriptorFactory.HUE_AZURE))
             .flat(true);
    Markeropition1.draggable(true);
    Markeropition2.draggable(true);
    gmap.moveCamera(CameraUpdateFactory.newLatLngZoom(sourcePosition,10)); 
    gmap.addMarker(Markeropition1);
    gmap.addMarker(Markeropition2);
}

1 个答案:

答案 0 :(得分:1)

可以从Api级别19在android中生成pdf文档。您可以从此链接http://developer.android.com/reference/android/graphics/pdf/package-summary.html

中获取参考