Skip to content

Instantly share code, notes, and snippets.

@yeoupooh
Created July 19, 2013 01:00
Show Gist options
  • Save yeoupooh/6034328 to your computer and use it in GitHub Desktop.
Save yeoupooh/6034328 to your computer and use it in GitHub Desktop.
Get QR code from Google chart.
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
public class QRImage {
public static InputStream getInputStream(String host, int port)
throws IOException {
String serverUrl = URLEncoder.encode(
String.format("http://%s:%s", host, port), "UTF-8");
URL url = new URL(
String.format(
"http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=%s&chld=H|0",
serverUrl));
InputStream in = new BufferedInputStream(url.openStream());
return in;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment