如何在浏览器中从 Http 请求打开流文件并从 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) {
}