NanoHTTPD

How to serve a file on sdcard using NanoHTTPD (inside Android)

两盒软妹~` 提交于 2019-11-27 00:23:32
问题 I've written a small Android server using NanoHTTPD. It can serve an HTML file well (web page located at sdcard/www/index.html). Can anybody please help me find out how can I serve an audio or video file instead of an html page using NanoHTTPD? Forgive me if the question seems silly, as I'm new to HTTP! Here is my server side code (I've replaced the webpage path to that of an audio file): package com.example.zserver; import java.io.BufferedReader; import java.io.File; import java.io

Using NanoHTTPD in Android

混江龙づ霸主 提交于 2019-11-27 00:22:52
I am trying to use NanoHTTP to serve up an HTML file. However, NanoHTTP is relatively un-documented, and I am new to Android. My question is, where do I store the html file, and how specifically can I serve it up using NanoHTTP. rendon A late answer but may be useful to others. Here is a simple hello Web Server, not exactly what you ask, but you can continue from here. The following program supposes you have a www directory in the root of the SD Card and a file index.html inside. Main activity Httpd.java : package com.inforscience.web; import android.app.Activity; import android.os.Bundle;

Using NanoHTTPD in Android

走远了吗. 提交于 2019-11-26 09:22:03
问题 I am trying to use NanoHTTP to serve up an HTML file. However, NanoHTTP is relatively un-documented, and I am new to Android. My question is, where do I store the html file, and how specifically can I serve it up using NanoHTTP. 回答1: A late answer but may be useful to others. Here is a simple hello Web Server, not exactly what you ask, but you can continue from here. The following program supposes you have a www directory in the root of the SD Card and a file index.html inside. Main activity

实战nanoHTTPD嵌入android app(3)

旧街凉风 提交于 2019-11-25 17:01:36
这篇咱们来解决image显示的问题。 6. 支持image 看看2000年的网易,是多么的朴(chou)素(lou)。 Image.png 所以支持主流的image也是必须滴! 有了上面的基础,其实加个图片也是个小case啦,也就是两个点: image的类型。从上面那个表,咱们可以看到这几个,只要把它们加到咱们的 if else 里去,这个问题就解决了: gif=image/gif jpg=image/jpeg jpeg=image/jpeg png=image/png 如何把image的内容返回 这个问题我也不会,不过咱会谷歌。经过搜索在stackoverflow里找到这个答案,其实也异常的简单,因为nanoHTTPD有一个函数: public static Response newFixedLengthResponse(IStatus status, String mimeType, InputStream data, long totalBytes) { return new Response(status, mimeType, data, totalBytes); } 有了这个,咱还怕啥,直接创建出一个InputStream给它,就能完成咱们的任务了: InputStream isr; try { isr = _mainContext.getAssets().open