1

嗨,我正在从 SD 卡的 GalleryView 中显示图像。但我想从驻留在服务器上的目录中获取。这是我的代码

 public ArrayList<String> getFilePaths() {
    ArrayList<String> filePaths = new ArrayList<String>();

    File directory = new File(
            android.os.Environment.getExternalStorageDirectory()
                    + File.separator + AppConstant.PHOTO_ALBUM);

    // check for directory
    if (directory.isDirectory()) {
        // getting list of file paths
        File[] listFiles = directory.listFiles();

        // Check for count
        if (listFiles.length > 0) {

            // loop through all files
            for (int i = 0; i < listFiles.length; i++) {

                // get file path
                String filePath = listFiles[i].getAbsolutePath();

                // check for supported file extension
                if (IsSupportedFile(filePath)) {
                    // Add image path to array list
                    filePaths.add(filePath);
                }
            }
        } else {
            // image directory is empty
            Toast.makeText(
                    _context,
                    AppConstant.PHOTO_ALBUM
                            + " is empty. Please load some images in it !",
                    Toast.LENGTH_LONG).show();
        }

    } else {
        AlertDialog.Builder alert = new AlertDialog.Builder(_context);
        alert.setTitle("Error!");
        alert.setMessage(AppConstant.PHOTO_ALBUM
                + " directory path is not valid! Please set the image directory name AppConstant.java class");
        alert.setPositiveButton("OK", null);
        alert.show();
    }

    return filePaths;
} 

在文件目录 = 新文件中,我如何使用服务器中的目录而不是 SD 卡。提前致谢

4

0 回答 0