Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7066019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:01:53+00:00 2026-05-28T05:01:53+00:00

I made code that download APK from ftp, and I`m trying to install it

  • 0

I made code that download APK from ftp, and I`m trying to install it after download. I wrote this for Honeycomb, so in every connection i have to use threads. How can I use startActivity in class within thread, or wait for thread to finish?

public class FTPapkDowload {
protected static final String TAG = "Tablet Development";
public FTPClient mFTPClient = null;
public FTPClient mFtp = null;

public void Start() {

Thread apkdowload = new Thread(new Runnable() {
        @Override
        public void run() {

            ftpConnect("mysite", "username", "password",21);
            Log.d(TAG, "Connected");
            ftpDownload("/httpdocs/Shamir/app.apk", "sdcard/Download/app.apk");
            ftpDisconnect();

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/Download/" + "app.apk")), "application/vnd.android.package-archive");
            startActivity(intent); //Here is the problem


        }

        //Connection
        public boolean ftpConnect(String host, String username,
                String password, int port) {
            try {

                mFTPClient = new FTPClient();
                mFTPClient.connect(host, port); 

                if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
                    boolean status = mFTPClient.login(username, password);

                    mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
                    mFTPClient.enterLocalPassiveMode();
                    return status;
                }
            } catch (Exception e) {
                Log.d(TAG, "Error: could not connect to host " + host);
            }

            return false;
        }


        //Downloading
        public boolean ftpDownload(String srcFilePath, String desFilePath) {
            boolean status = false;
            try {

                FileOutputStream desFileStream = new FileOutputStream(
                        desFilePath);
                status = mFTPClient
                        .retrieveFile(srcFilePath, desFileStream);
                desFileStream.close();
                return status;
            } catch (Exception e) {
                Log.d(TAG, "download failed");
            }

            return status;
        }



        public boolean ftpDisconnect() {

            try {
                mFTPClient.logout();
                mFTPClient.disconnect();
                Log.d(TAG, "Disconected from FTP on apk Download");

                return true;
            } catch (Exception e) {
                Log.d(TAG,"Error occurred while disconnecting from ftp server on apk download.");
            }

            return false;
        }

    });

    apkdowload.start();
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:01:54+00:00Added an answer on May 28, 2026 at 5:01 am

    You can use a handler:

    private Handler handler = new Handler(){
            public void handleMessage(Message msg)
            {
    
            }
        };
    

    When your thread is done running the code it needs to call: handler.sendEmptyMessage(0);

    More info: http://developer.android.com/reference/android/os/Handler.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a code that translate strings to match each word from the array
I've made some experimental code that I would like to save in the repository,
We've got a fairly large amount of code that just made the jump to
I've made some function that generates an email template. Code it generates is pure
I was looking at the Java code for LinkedList and noticed that it made
I'm debugging someone else's code for a web page that is made with ASP.NET
I made this code with jQuery to fade images ( but not the one
I am trying to make a FTP script in Python3.2 that connects to a
i have to write some code that initialize my data app. This must be
I am trying to get my script to download subtitles from www.subscene.com. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.