0

I use Connect-SDK-Android-API-Sampler and share an image into a TV using mediaURL "www.example.com/image.jpg".

How I could share my local image from device?

DuoBlood
  • 71
  • 1
  • 5
  • This appears to be covered in [the FAQ of that SDK.](http://connectsdk.com/docs/android/faq/) – Dan Getz May 14 '15 at 17:33
  • Thanks for the quick response, I read the FAQ and did not see it. I thought about that solution but hoped there is another solution for my problem – DuoBlood May 15 '15 at 09:46

1 Answers1

0

A solution of my problem is Web Server. I used a 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");
        }
    }
}
DuoBlood
  • 71
  • 1
  • 5
  • I have used Nanohttpd as well and it is working fine for every device except, Samsung and FireTV, it gives me Internal server error. have you got this problem while working on this? – Zurmati Nov 29 '22 at 06:24