Home » Android » Android Class to create pdf file and save it to ftp-Exceptionshub

Android Class to create pdf file and save it to ftp-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment


In Activity i have a button to open a ScanningActivity for scan document and in ActivityResult i create a pdf file and save it to an fpt server. For now it is ok but i’d like to make the same in others activities. How can i put downloadTask in separate file and how use it from another activities?

public void onCreate(Bundle savedInstanceState) {

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {


protected void startScan(int preference) {
    Intent intent = new Intent(this, ScanActivity.class);
    intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, preference);
    startActivityForResult(intent, REQUEST_CODE);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

            new CreatingPdf().execute();            

public void download(){
        String address="",u="user",p="parola",serverPath=comandanr+".pdf",destination=(Environment.getExternalStoragePublicDirectory(

   downloadTask async=new downloadTask();

class downloadTask extends AsyncTask<String, Void, String> {

    private ProgressDialog prg;

    protected void onPreExecute() {
        prg = new ProgressDialog(DetaliiActivity.this);
        prg.setMessage("Download comanda " + comandanr);

    protected String doInBackground(String... params) {
        try {
            easyFTP ftp = new easyFTP();               
            ftp.connect(params[0], params[1], params[2]);
            ftp.downloadFile(params[3], params[4]);
            return new String("Download Successful");
        } catch (Exception e) {
            String t = "Failure : " + e.getLocalizedMessage();
            return t;

    protected void onPostExecute(String str) {

    private void openpdf(){

How to&Answers: