Solution to quickly read specific information from Android live app source code

In order to quickly read specific information, display or verify it in the source code of cloudleopard live app, the most popular solution is to "scan QR code". In this way, users do not need to use complex memory and logic. They can realize the requirements with a gentle sweep. It is very common in all kinds of apps.

So today, let's briefly introduce how to quickly realize the function of displaying QR code, scanning and reading information in the source code of Android live app

Here I would like to introduce that at present, the official Android Google has its own QR code scanning library, but it is not convenient to use. Therefore, here I would like to introduce the QR code scanning library being used by cloudleopard technology. This library is used in cloudleopard live app source code, cloudleopard short video source code, cloudleopard play source code and cloudleopard voice social source code - "bgaqrcode Android", It can realize the basic functions of generating QR code, scanning QR code and identifying picture QR code

Next, let's introduce how to use it at the code level:

First, put maven {URL‘ https://jitpack.io ’}Add to root build In gradle's repositories
In app build Add the following dependencies to gradle. The "lastversion" at the end refers to the latest version of the library. Please replace it yourself
ZXing version:

dependencies {
  Implementation 'com.github.bingoogolapple.BGAQRCode-Android:zxing:latestVersion'
}

ZBar version

dependencies {
    implementation 'com.github.bingoogolapple.BGAQRCode-Android:zbar:latestVersion'
}

Ps: because the two versions have different emphases, two versions are provided.

Then, it is used in the layout file. Since the author is used to using the ZXing version, the following codes are the use methods of the ZXing version:

ZXing: 
<cn.bingoogolapple.qrcode.zxing.ZXingView
    android:id="@+id/zxingview"
    style="@style/MatchMatch"
    app:qrcv_animTime="1000"
    app:qrcv_borderColor="@android:color/white"
    app:qrcv_borderSize="1dp"
    app:qrcv_cornerColor="@color/colorPrimaryDark"
    app:qrcv_cornerLength="20dp"
    app:qrcv_cornerSize="3dp"
    app:qrcv_maskColor="#33FFFFFF"
    app:qrcv_rectWidth="200dp"
    app:qrcv_scanLineColor="@color/colorPrimaryDark"
    app:qrcv_scanLineSize="1dp"
    app:qrcv_topOffset="90dp" />

Common methods are:

/**
 * ZXingView Set the recognized format. For detailed usage, see onClick method in zxingdemo TestScanActivity
 *
 * @param barcodeType Recognized format
 * @param hintMap     barcodeType Is barcodetype This value must be specified when custom
 */
public void setType(BarcodeType barcodeType, Map<DecodeHintType, Object> hintMap)

/**
 * Sets the proxy for scanning QR codes
 *
 * @param delegate Agent for scanning QR code
 */
public void setDelegate(Delegate delegate)

/**
 * Show scan box
 */
public void showScanRect()

/**
 * Hide scan box
 */
public void hiddenScanRect()

/**
 * Turn on the rear camera to start preview, but did not start recognition
 */
public void startCamera()

/**
 * Open the specified camera to start preview, but did not start recognition
 *
 * @param cameraFacing  Camera.CameraInfo.CAMERA_FACING_BACK or Camera.CameraInfo.CAMERA_FACING_FRONT
 */
public void startCamera(int cameraFacing)

/**
 * Turn off the camera preview and hide the scan box
 */
public void stopCamera()

/**
 * Start identification
 */
public void startSpot()

/**
 * Stop recognition
 */
public void stopSpot()

/**
 * Stop recognition and hide the scan box
 */
public void stopSpotAndHiddenRect()

/**
 * Display the scan box and start recognition
 */
public void startSpotAndShowRect()

/**
 * flash on 
 */
public void openFlashlight()

/**
 * Turn off the astigmatism lamp
 */
public void closeFlashlight()

/**
 * Parse local picture QR code. Returns the content in the QR code picture or null
 *
 * @param picturePath Local path of QR code image to be parsed
 */
public void decodeQRCode(String picturePath)

/**
 * Parse Bitmap QR code. Returns the content in the QR code picture or null
 *
 * @param bitmap QR code image to parse
 */
public void decodeQRCode(Bitmap bitmap)
QRCodeView.Delegate Agent for scanning QR code

/**
 * Process scan results
 *
 * @param result When the camera scans the code, as long as the method is called back, the result must have a value and will not be null. The result may be null when parsing a local picture or Bitmap
 */
void onScanQRCodeSuccess(String result)

/**
 * Camera ambient brightness changes
 *
 * @param isDark Is it dimmed
 */
void onCameraAmbientBrightnessChanged(boolean isDark);

/**
 * Error processing open camera
 */
void onScanQRCodeOpenCameraError()

In the cloud leopard live app source code, the actual code is:

private ZXingView mZXingView;
 mZXingView.startCamera(); // Turn on the rear camera to start preview, but did not start recognition
//        mZXingView.startCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); //  Turn on the front camera to start preview, but it does not start recognition
        mZXingView.startSpotAndShowRect(); // Display the scan box and start recognition

 @Override
    public void onScanQRCodeSuccess(final String result) {
//The scanned result is a string, and then operate on the string as needed
        L.e(TAG, "result:" + result);
        if (TextUtils.isEmpty(result)){
            ToastUtil.show(WordUtil.getString(R.string.qr_code_9));
            return;
        }
        String prefix = "uid=";
        if (result.startsWith(prefix)){
            final String toUid  = result.substring(prefix.length()); 
        }
//        vibrate();
//        mZXingView.startSpot(); //  Start identification
    }

    @Override
    protected void onResume() {
        super.onResume();
        startScan();
    }

    @Override
    public void onCameraAmbientBrightnessChanged(boolean isDark) {
        // Here is to show whether the environment is too dark by modifying the prompt copy. The access party can also realize other interaction effects according to the value of isDark
        String tipText = mZXingView.getScanBoxView().getTipText();
        String ambientBrightnessTip = "\n The environment is too dark, please turn on the flash";
//        L.e(TAG,"isDark--->"+isDark);
    }

    @Override
    public void onScanQRCodeOpenCameraError() {
        L.e(TAG, "Error opening camera");
    }

Finally, don't forget to destroy after use:

mZXingView.onDestroy(); // Destroy QR code scan control

The above is the whole content of this article. If you need to buy the source code of cloudleopard live app or consult relevant matters, please contact cloudleopard technology.

Keywords: Python Java iOS Android Design Pattern

Added by PHPFreaksMaster on Wed, 19 Jan 2022 12:02:34 +0200