Open a mini-program via a promotional QR code
For promotional purposes, you can create a QR code for your mini-program on Mini Program Platform and hand it out to consumers. However, the content of the promotional QR code is an encoded URL, which cannot be used to open a mini-program directly.
To allow consumers to open a mini-program via a promotional QR code, Mini Program Platform provides the following two APIs for Android IAPMiniProgram SDK:
- canDecodeUrl: Call this API to verify if the QR code can be decoded.
- decodeUrlContent: Call this API to decode the QR code.
Procedures
Step 1: Verify if the QR code can be decoded
To verify if the QR code can be decoded by Android IAPMiniProgram SDK and used to open a mini-program, you need to integrate the canDecodeUrl API.
For more information, see canDecodeUrl.
Step 2: Decode the QR code
For QR codes that can be decoded, you need to integrate the decodeUrlContent API for decoding. If the decoding succeeds, the decoded URL is returned via onDecodeSuccess; otherwise, the decoding result is returned via onDecodeFailed.
For more information, see decodeUrlContent.
Step 3: Open the mini-program
After receiving the decoded URL, call the openUrl API to open the mini-program.
For more information, see openUrl.
Sample
The following sample shows how the APIs above cooperate to decode a promotional QR code and open a mini-program.
// the scanning result of the QR Code
String scanResult = ...
// test whether the URL can be decoded
if (GriverDecodeUrl.canDecodeUrl(scanResult)) {
GriverDecodeUrl.decodeUrlContent(scanResult, new GriverDecodeUrlCallback() {
@Override
public void onDecodeSuccess(String url) {
// use the decoded URL to open a mini program
Bundle bundle = new Bundle();
Griver.openUrl(activity, url, bundle);
}
@Override
public void onDecodeFailed(int errorCode, String errorMessage) {
Log.d(TAG, "decodeUrlContent failed");
}
}
}