uzayvdjcxl 发表于 2016-6-8 07:46:33

Ftp下载图片并显示

  private void updateResultsInUi() { 
 

 
  TextView jpgName = (TextView)findViewById(R.id.jpgname);       
  ImageView jpgView = (ImageView)findViewById(R.id.jpgview); 
  String myJpgPath = "/sdcard/test.jpg";               
      jpgName.setText(myJpgPath); 
  BitmapFactory.Options options = new BitmapFactory.Options();   
  options.inSampleSize = 2; 
  Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options); 
  jpgView.setImageBitmap(bm); 
    } 


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);      
setContentView(R.layout.main);
this.pd = ProgressDialog.show(this, "Working...", "*** Downloading Data...", true, false);
new DownloadTask().execute(" parameters needed for download");
}
private class DownloadTask extends AsyncTask<String, Void, Object> {
protected Void doInBackground(String... args) {
Log.d("********Jorgesys", "Background thread starting......");
startLongRunningOperation();   
return null;         
}
protected void onPostExecute(Object result) {
Log.d("********Jorgesys", "onPostExecute......");
if (Splash.this.pd != null) {
Splash.this.pd.dismiss();
}
updateResultsInUi();
}
}

protected void startLongRunningOperation() {
try
{
ftp = new FTPClient();
ftp.connect(host);
ftp.login("username", "password");
ftp.changeDirectory("public_ftp");
ftp.download("test.jpg", new java.io.File("/sdcard/test.jpg"));
}
catch(Exception e)
{               
}
}

  
页: [1]
查看完整版本: Ftp下载图片并显示