Author: zemna
Date: April 17, 2021
Share this:

해당 링크로의 연결정보를 가지고 있는 QR Code 이미지를 생성하여 반환하는 클래스. 스마트폰에서 QR Code 리더기 어플을 이용하여 찍으면 해당 링크로 이동이 가능하다.


[code language="java"] package net.zemna.android.appadviser;

import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection;

import android.graphics.Bitmap; import android.graphics.BitmapFactory;

public final class QRCodeFactory {

public static Bitmap loadQRImage(String url, int width, int height) {

String image_URL="http://chart.apis.google.com/chart?chs=" + width + "x" + height + "&cht=qr&chl=" + url;

BitmapFactory.Options bmOptions; bmOptions = new BitmapFactory.Options(); bmOptions.inSampleSize = 1; Bitmap bm = loadImage(image_URL, bmOptions);

return bm; }

private static Bitmap loadImage(String url, BitmapFactory.Options options) { Bitmap bitmap = null; InputStream in = null; try { in = OpenHttpConnection(url); bitmap = BitmapFactory.decodeStream(in ,null, options); in.close(); } catch (IOException e) { } return bitmap; }

private static InputStream OpenHttpConnection(String strUrl) throws IOException { InputStream inputStream = null; URL url = new URL(strUrl); URLConnection conn = url.openConnection();

try { HttpURLConnection httpConn = (HttpURLConnection)conn; httpConn.setRequestMethod("GET"); httpConn.connect();

if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { inputStream = httpConn.getInputStream(); } } catch (Exception e) { } return inputStream; } } [/code]

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *

Let's connect and create
something awesome together!
2023 - Copyright, All Rights Reserved, Made by ZEMNA.NET with ❤️
crossmenu linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram