如何从HTTP请求的浏览器 ,并从PC传送打开流文件,以Android设备如何将文件从PC传输到Android设备
public class WebServer extends Thread {
private static final String SERVER_NAME = "AndWebServer";
private static final String MESSAGE_PATTERN = "/message*";
public WebServer(Context context, NotificationManager notifyManager){
super(SERVER_NAME);
this.setContext(context);
this.setNotifyManager(notifyManager);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
serverPort = Integer.parseInt(pref.getString(Constants.PREF_SERVER_PORT, "" + Constants.DEFAULT_SERVER_PORT));
httpproc = new BasicHttpProcessor();
httpContext = new BasicHttpContext();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
httpService = new HttpService(httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory());
registry = new HttpRequestHandlerRegistry();
registry.register(MESSAGE_PATTERN, new MessageCommandHandler(context,
httpService.setHandlerResolver(registry);
}
@Override
public void run() { ... }
}
public MessageCommandHandler(Context context, NotificationManager notifyManager){
this.context = context;
this.notifyManager = notifyManager;
@Override
public void handle(HttpRequest request, HttpResponse response, HttpContext httpContext) throws HttpException, IOException {
String uriString = request.getRequestLine().getUri();
Uri uri = Uri.parse(uriString);
String message = URLDecoder.decode(uri.getQueryParameter("msg"));
// get open stearm file and save
AppLog.logString("Message URI: " + uriString);
displayMessage(message);
HttpEntity entity = new EntityTemplate(new ContentProducer() {....
}
});
response.setHeader("Content-Type", "text/html");
response.setEntity(entity);
}
protected void displayMessage(final String message) {
}
请提供更多详情。你有Android应用程序吗? HTML从哪里来?你真的在使用Android设备运行HTTP服务器吗? –
http://code.google.com/p/krvarma-android-samples/source/browse/trunk/aws/src/com/varma/android/aws/?r=80 我从上面获得帮助。 但我没有发现任何关于文件传输的内容。 –
你能用3-4句话回答我的问题吗?我并不想完成整个项目,也没有人会这样做。 –