android - Connect SDK: share local image -


i use connect-sdk-android-api-sampler , share image tv using mediaurl "www.example.com/image.jpg".

how share local image device?

a solution of problem web server. used nanohttpd library.

public class webserver extends nanohttpd {      private int port;      public webserver(int port) {         super(port);         this.port = port;     }      @override     public response serve(ihttpsession session) {         method method = session.getmethod();         switch (method) {             case get:                 string path = session.geturi().replace(utils.getipaddress(true) + ":" + port, "");                  //todo refactoring                 string type = filenameutils.getextension(path);                 string filepath = environment.getexternalstoragedirectory() + path;                 string contenttype = "";                 if (type.equals("jpg") || type.equals("jpeg") || type.equals("png") || type.equals("gif") || type.equals("tiff"))                     contenttype = "image/" + type;                 else                     return new response(response.status.bad_request, nanohttpd.mime_plaintext, "httperror: http 8: bad request");                  if (fileinputstream != null)                     fileinputstream.close();                 try {                     fileinputstream = new fileinputstream(filepath);                 } catch (filenotfoundexception e) {                     new response(response.status.bad_request, nanohttpd.mime_plaintext, "httperror: http 8: bad request");                 }                 return new response(response.status.ok, contenttype, fileinputstream);              default:                 return new response(response.status.method_not_allowed, nanohttpd.mime_plaintext, "httperror: http 405: method not allowed");         }     } } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -