Android 如何生成重定向到URL的二维码?
我一直在使用QR生成器应用程序,它对我来说很好 我的问题是,如何生成二维码,在二维码阅读器扫描后重定向到网站 这是我的QR生成器代码,它只生成简单的文本:Android 如何生成重定向到URL的二维码?,android,bitmap,Android,Bitmap,我一直在使用QR生成器应用程序,它对我来说很好 我的问题是,如何生成二维码,在二维码阅读器扫描后重定向到网站 这是我的QR生成器代码,它只生成简单的文本: Bitmap getQRCode(Context context, String type, String value) throws WriterException { BitMatrix bitMatrix; try { bitMatrix = new MultiFormatWriter().encode
Bitmap getQRCode(Context context, String type, String value) throws WriterException {
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(value, BarcodeFormat.DATA_MATRIX.QR_CODE, QR_DIM, QR_DIM, null);
} catch (IllegalArgumentException e) {
return null;
}
int bitMatrixHeight = bitMatrix.getHeight();
int bitMatrixWidth = bitMatrix.getWidth();
int pixels[] = new int[bitMatrixHeight * bitMatrixWidth];
for (int y = 0; y < bitMatrixHeight; y++) {
int offset = y * bitMatrixWidth;
for (int x = 0; x < bitMatrixWidth; x++) {
pixels[offset + x] = bitMatrix.get(x, y) ?
context.getResources().getColor(R.color.QRCodeBlackColor):context.getResources().getColor(R.color.QRCodeWhiteColor);
}
}
Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
bitmap.setPixels(pixels, 0, 500, 0, 0, bitMatrixWidth, bitMatrixHeight);
return bitmap;
}
Bitmap getQRCode(上下文上下文、字符串类型、字符串值)引发WriterException{
位矩阵;位矩阵;
试一试{
bitMatrix=new MultiFormatWriter().encode(值、条码格式、数据矩阵、QR码、QR码、QR码、null);
}捕获(IllegalArgumentException e){
返回null;
}
int bitMatrixHeight=bitMatrix.getHeight();
int bitMatrixWidth=bitMatrix.getWidth();
整数像素[]=新整数[bitMatrixHeight*bitMatrixWidth];
对于(int y=0;y
谢谢大家。使用
然后
您可以读取二维码并使用结果打开web视图。
我还没有试过,但我希望这能帮上忙。MarGin非常感谢你,显然,当你用URL生成QR时,如果QR阅读器支持,它会自动重定向,所以QR本身与重定向无关。我试着从三星Bixby读取一个URL QR,它会自动将我重定向到该链接,并在另一个QR阅读器上进行了尝试,结果显示它是一个URL