public static Bitmap getQRCodeBitmap(String address, Activity activity) { final DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final int width = displaymetrics.widthPixels; final Intent intent = new Intent(Intents.Encode.ACTION); intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intent.putExtra(Intents.Encode.DATA, address); intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); try { Log.i("", "Initializing QR: " + width); final QRCodeEncoder encoder = new QRCodeEncoder(activity, intent, width, false); return encoder.encodeAsBitmap(); } catch (Exception e) { } return null; }
private Bitmap generateQRCode(String uri) { final float REG_RES = 2.0f; Resources resources = getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = null; int qrCodeDimension = (scale <= REG_RES) ? 440 : 880; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); try { bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } return bitmap; }
private Bitmap generateQRCode(String uri) { Bitmap bitmap = null; int qrCodeDimension = 280; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); try { bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } return bitmap; }
private Bitmap generateQRCode(String uri) { Bitmap bitmap = null; int qrCodeDimension = 150; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); try { bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } return bitmap; }
private Bitmap generateQRCode(String uri) { Bitmap bitmap = null; int qrCodeDimension = 380; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); try { bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } return bitmap; }
/** * Share the data from the intent. * * @param intent */ private void share(Intent intent, final Context context) { // try to start server String action = intent.getAction(); String type = intent.getType(); if (Intent.ACTION_SEND.equals(action) && type != null) { mMimeType = type; if (type.startsWith("text/x-vcard")) { handleSendContactText(intent); // Handle text being sent } else if (type.startsWith("text/")) { handleSendRawText(intent); // Handle text being sent } else if (type.startsWith("image/")) { handleSendFile(intent); // Handle single image being sent } else if (type.startsWith("audio/")) { handleSendFile(intent); // Handle single audio being sent } else if (type.startsWith("video/")) { handleSendFile(intent); // Handle single video being sent } else if (type.startsWith("application/")) { handleSendFile(intent); // Handle single video being sent } NetworkUtils.WifiDetails wifiDetails = NetworkUtils .getWifiDetails(mContext); if (wifiDetails != null) { // detect wifi network name notifyOnServerWifiNetworkNameDetected(wifiDetails.ssid); // security string mRandomString = ("" + Math.abs(new Random().nextInt())).substring(0, 4); mRealUrl = URL_BEGIN + wifiDetails.ipAddress + ":" + ShAIReConstants.SERVER_PORT + "/" + mRandomString; // generate shorten url UrlShortener.getInstance(mContext).shortenUrlonTinyUrl(mRealUrl, this); // generate QR code try { Intent intentText = new Intent(); intentText.setAction(Intents.Encode.ACTION); intentText.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); intentText .putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intentText.putExtra(Intents.Encode.DATA, mRealUrl); mQrCodeEncoder = new QRCodeEncoder(mContext, intentText, 500, false); Bitmap qrCode = mQrCodeEncoder.encodeAsBitmap(); notifyServerUrlQRCodeGenerated(qrCode); } catch (WriterException e) { notifyOnServerUrlQRCodeGeneratioFailed(); } } else { notifyError(mContext .getString(R.string.please_make_sure_your_wifi_is_actvivated)); } } else { notifyError(mContext.getString(R.string.you_cant_share_this)); } }