Implementing the Huawei QR Scanner
Mobile devices manufactured by Huawei require a custom scanner to successfully scan QR codes. The capability is integrated into HYPR SDK for Android, so you just need to make the build.gradle
configuration changes described below in order to enable it from the top-level app.
Implementation
HYPR SDK for Android uses a device model check to determine if the HYPR-implemented Huawei QR Scanner should be used instead of the default Firebase scanner.
string manufacturer = android.os.Build.MANUFACTURER;
manufacturer.toLowerCase().equals("huawei"); // if true, use the Huawei QR Scanner
Configuration Changes
For additional information, see the Huawei documentation here.
Configure the Maven Repository Address for the Huawei Mobile Services (HMS) SDK
-
Open the
build.gradle
file in the root directory of your Android Studio project. -
Under allprojects > repositories, configure the Maven repository address for the HMS SDK:
allprojects {
repositories
{
google()
jcenter()
maven {
url 'https://developer.huawei.com/repo/'
}
}
}
- Under buildscript > repositories, configure the Maven repository address for the HMS SDK:
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://developer.huawei.com/repo/'
}
}
}
- Under buildscript > dependencies, add the following dependency:
buildscript {
dependencies {
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
}
Add Build Dependencies
-
Open the
build.gradle
file in the/app
directory. -
Add the hms:scan dependency:
dependencies {
implementation 'com.huawei.hms:scan:{version}'
}
- Add the AppGallery Connect plugin dependency to the file header:
apply plugin: 'com.huawei.agconnect'
Synchronize
Open the modified build.gradle
file again and you’ll find a Sync Now link in the upper right corner of the page. Click Sync Now and wait until synchronization is complete. If an error occurs, check the network connection and the configurations in the build.gradle
file.
Configure Obfuscation Scripts
Add configurations to exclude the HMS SDK from obfuscation:
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.**{*;}
Associated Error Codes
Error Code | Cause | Recommended Resolution |
---|---|---|
114106 | Huawei barcode scanner failure. | Internal SDK error. Check the logs for more details. |