user3194123
user3194123

Reputation: 41

Send pdf from Java Server to Android Device

What are the different ways to send pdf from Java Server to Android Device and Which one the Best way

( Mostly Using Spring Integration)

Upvotes: 1

Views: 316

Answers (2)

sytolk
sytolk

Reputation: 7383

To send (initiate download from server side to Android) its need to have Android application installed with Google Cloud Messages GCM and push notification message from server side to Android = start download from some link and next your Android application will start download (pdf can be accessible from web service with/without security -like JaxRS, Apache www root dir without security or some ftp too)

Upvotes: 0

ajitksharma
ajitksharma

Reputation: 2019

You can try this, one way using Jax RS, It is not using JSON. It let the file downloaded to the device.

@GET
@Path("/{fileName}/excel") 
//Your Proper URL,using the fileName let you the download the specific pdf
@Produces("application/pdf")
public Response getFileInPDFFormat(@PathParam("fileName") String fileName) 
{
    String filePath="";// Your File Path

    //Put some validations here such as invalid file name or missing file name
    if(fileName == null || fileName.isEmpty())
    {
        ResponseBuilder response = Response.status(Status.BAD_REQUEST);
        return response.build();
    }

    File file = new File(filePath);

    ResponseBuilder response = Response.ok((Object) file);
    response.header("Content-Disposition", "attachment; filename='"+fileName+"'");


    return response.build();
}

Upvotes: 2

Related Questions