Android ftp文件下载结果为黑屏

Android ftp文件下载结果为黑屏,android,ftp,download,screen,Android,Ftp,Download,Screen,我正在从ftp服务器下载一个文件。下载代码工作正常,但在下载代码屏幕没有显示任何内容后,屏幕变黑。此外,下载函数不会返回真值,即使文件保存在指定的目录中 public class FTPClass{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_file_player);

我正在从ftp服务器下载一个文件。下载代码工作正常,但在下载代码屏幕没有显示任何内容后,屏幕变黑。此外,下载函数不会返回真值,即使文件保存在指定的目录中

  public class FTPClass{
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_file_player);

                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Intent intent = getIntent();
    dirname = intent.getStringExtra("currentDirName");


    MyFTPClient mftp = new MyFTPClient();
    createPath = mftp.getAppRootPath().concat("/"+ dirname);
    mftp.setCurrentDir(createPath);
    System.out.println(mftp.ftpChangeDirectory(createPath));

    FTPFile[] farr = mftp.ftpListAllFiles();
    System.out.println(farr.length);

    for(int i = 0; i<farr.length;i++){
        System.out.println("SRC: "+createPath+"/"+farr[i].getName());

        String src = createPath+"/"+farr[i].getName();
        System.out.println("DEST: "+"/data/data/com.example.ftpplayer" + "/app_"+dirname);
        String dest ="/data/data/com.example.ftpplayer" + "/app_"+dirname+"/"+farr[i].getName();
        System.out.println(mftp.downloadFile(src,dest));
    }
}
}

public class CallingIntent extends Activity{
        System.out.println("In item click ");
            Intent intent = new Intent(getApplicationContext(), FTPClass.class);
            String dir = ((TextView) view).getText().toString();
            intent.putExtra("currentDirName", dir);
            startActivity(intent);

}
 public class MyFTPClient{

 public boolean downloadFile(String srcPath , String destPath){

    try {
        FileOutputStream fos = new FileOutputStream(destPath);
        System.out.println(mftp.retrieveFile(srcPath, fos)); // retrieve file doesn't return true
        fos.flush();
        fos.close();
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }catch(IOException e){
        e.printStackTrace();
    }
    return false;
}

}
公共类FTPClass{
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u file\u player);
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
Intent=getIntent();
dirname=intent.getStringExtra(“currentDirName”);
MyFTPClient mftp=新的MyFTPClient();
createPath=mftp.getApprotPath().concat(“/”+dirname);
mftp.setCurrentDir(createPath);
System.out.println(mftp.ftpchangeditory(createPath));
FTPFile[]farr=mftp.ftpListAllFiles();
系统输出打印长度(farr.长度);

对于(int i=0;i您需要在后台线程上运行代码,尝试使用asyncTask。

FTPClass可能应该是have
extends Activity
,CallingContent可能应该有一个
onCreate
方法。我没有尝试过,但我认为这不应该按原样运行。是的。FTPClass和CallingContent是一个活动。我是据推测,code.Is Strictmode策略是无法从retrieveFile方法获取true的原因。此外,日志中未显示任何错误。