doutuichan2681 2015-11-04 16:34
浏览 114

Android从Web服务器获取目录内容

Actually I'm developing an app for android.

The app should display all images from a specific directory stored in a webspace.

Example

Host: www.example.org

Folder: /images

Foldercontent

/images/file.png

/images/file2.png

/images/folder/file3.png

I already found out how to display a single image provided by a URL (used the Picasso library)

ImageView appImage = new ImageView(getActivity());

Picasso.with(getActivity()).load("http://www.example.org/images/file.png").into(appImage);

Now my question is, how can I display all images located in a directory and all subfolders?

I have implemented a PHP Script on the Server which provides my the name of all files located in the directory as a text form, but how do I get those names in Android? How can I call the PHP Script and store the output in a String Array for example?

Or is there a better solution for this, without a PHP Script?

Regards

  • 写回答

1条回答 默认 最新

  • dongshengyin0147 2015-11-04 16:42
    关注

    The PHP Script should be the best approach.

    If it acts as a Rest webservice (it should) you just need to perform a really common task (Calling REST Services)

    Here is a really simple implementation using the URL class (Its made from my thoughts so it probably has errors, long time since i used BufferedReader)

    URL url = new URL("yourURLString");
    BufferedReader br = new BufferedReader(url.openConnection().getInputStream());
    String response = "";
    String readed = null;
    readed = br.read();
    while(readed != null)
    {
        response += readed;
    }
    

    After that you should have the response of your script on the response String, then parse it to get the values you need and show it in your app.

    Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊